41
Universität Hamburg MIN-Fakultät Department Informatik Git Version Control System Introduction to the Git Version Control System Sebastian Rockel [email protected] University of Hamburg Faculty of Mathematics, Informatics and Natural Sciences Department of Informatics Technical Aspects of Multimodal Systems November 8, 2011 S. Rockel 1

IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Git Version Control System

Introduction to the Git Version Control System

Sebastian [email protected]

University of HamburgFaculty of Mathematics, Informatics and Natural Sciences

Department of InformaticsTechnical Aspects of Multimodal Systems

November 8, 2011S. Rockel 1

Page 2: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Git Version Control System

OutlineIntroductionConfiguration

User SetupRepository Setup

Basic TasksCommonly used CommandsBranches

Special UsecasesGUITagsRemote Repositories

S. Rockel 2

Page 3: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Introduction Git Version Control System

IntroductionGit is..

I from Linus Torwalds

I local (and remote if necessary)

I fast (well..)

I Comprehensiv Howto @ http://linux.yyz.us/git-howto.html

S. Rockel 3

Page 4: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Introduction Git Version Control System

IntroductionGit is..

I from Linus Torwalds

I local (and remote if necessary)

I fast (well..)

I Comprehensiv Howto @ http://linux.yyz.us/git-howto.html

S. Rockel 3

Page 5: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Introduction Git Version Control System

IntroductionGit is..

I from Linus Torwalds

I local (and remote if necessary)

I fast (well..)

I Comprehensiv Howto @ http://linux.yyz.us/git-howto.html

S. Rockel 3

Page 6: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Introduction Git Version Control System

IntroductionGit is..

I from Linus Torwalds

I local (and remote if necessary)

I fast (well..)

I Comprehensiv Howto @ http://linux.yyz.us/git-howto.html

S. Rockel 3

Page 7: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Introduction Git Version Control System

Insights

I IndexI under:� �<r epos i to ry d i r >/. g i t / . .� �

I HashesI every version in the index has its own unique SHA1 hashI abbreviate it with the first few character

S. Rockel 4

Page 8: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Introduction Git Version Control System

Insights

I IndexI under:� �<r epos i to ry d i r >/. g i t / . .� �

I HashesI every version in the index has its own unique SHA1 hashI abbreviate it with the first few character

S. Rockel 4

Page 9: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Configuration - User Setup Git Version Control System

OutlineIntroductionConfiguration

User SetupRepository Setup

Basic TasksCommonly used CommandsBranches

Special UsecasesGUITagsRemote Repositories

S. Rockel 5

Page 10: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Configuration - User Setup Git Version Control System

Git per User Setup$HOME/.gitconfig� �

1 [ gui ]recentrepo = / Users / sebas t i an / projekt090406

3 s p e l l i n g d i c t i o n a r y = en[ user ]

5 emai l = rocke l@ in fo rmat ik . uni−hamburg . dename = Sebast ian Rockel

7 [ merge ]t o o l = open d i f f

9 summary = t rue[ c o l o r ]

11 d i f f = autos ta tus = auto

13 branch = auto[ core ]

15 a u t o c r l f = i nput� �S. Rockel 6

Page 11: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Configuration - Repository Setup Git Version Control System

OutlineIntroductionConfiguration

User SetupRepository Setup

Basic TasksCommonly used CommandsBranches

Special UsecasesGUITagsRemote Repositories

S. Rockel 7

Page 12: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Configuration - Repository Setup Git Version Control System

Exclude Files

per repo: <repository dir>/.git/info/exclude� �# L ines that s t a r t with ’# ’ are comments .# For a p r o j e c t mostly i n C , the f o l l o w i n g# would be a good set of exc lude patte rns# (uncomment them i f you want to use them ) :# ∗ . [ oa ]∗~∗ . swp� �per (sub)dir: <some repo (sub) dir>/.gitignore� �. metadata//doc/� �

S. Rockel 8

Page 13: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Configuration - Repository Setup Git Version Control System

Exclude Files

per repo: <repository dir>/.git/info/exclude� �# L ines that s t a r t with ’# ’ are comments .# For a p r o j e c t mostly i n C , the f o l l o w i n g# would be a good set of exc lude patte rns# (uncomment them i f you want to use them ) :# ∗ . [ oa ]∗~∗ . swp� �per (sub)dir: <some repo (sub) dir>/.gitignore� �. metadata//doc/� �

S. Rockel 8

Page 14: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

OutlineIntroductionConfiguration

User SetupRepository Setup

Basic TasksCommonly used CommandsBranches

Special UsecasesGUITagsRemote Repositories

S. Rockel 9

Page 15: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

Basic Tasks

clone a remote repository:� �g i t c lone

git@github .com : buzzer/Robot−Col laborat ion . g i t� �get the latest changes from remote repo:� �g i t fetch [ $branch|−− a l l ]� �� �g i t p u l l [ opt iona l ssh/https path again ]� �

S. Rockel 10

Page 16: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

Basic Tasks

clone a remote repository:� �g i t c lone

git@github .com : buzzer/Robot−Col laborat ion . g i t� �get the latest changes from remote repo:� �g i t fetch [ $branch|−− a l l ]� �� �g i t p u l l [ opt iona l ssh/https path again ]� �

S. Rockel 10

Page 17: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

Basic Tasks (cont’d)

stage changes for commit:� �g i t add . |− i | $ f i l e s� �commit changes:� �g i t commit −a|−m ’message ’� �revert version, checkout:� �g i t checkout [− f ] . | $branch | $hash� �

S. Rockel 11

Page 18: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

Basic Tasks (cont’d)

stage changes for commit:� �g i t add . |− i | $ f i l e s� �commit changes:� �g i t commit −a|−m ’message ’� �revert version, checkout:� �g i t checkout [− f ] . | $branch | $hash� �

S. Rockel 11

Page 19: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

Basic Tasks (cont’d)

stage changes for commit:� �g i t add . |− i | $ f i l e s� �commit changes:� �g i t commit −a|−m ’message ’� �revert version, checkout:� �g i t checkout [− f ] . | $branch | $hash� �

S. Rockel 11

Page 20: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

Basic Tasks (cont’d)Get the current repo status

Show current branch, changes, untracked files:� �g i t s tatus� �Show commit history:� �g i t log� �Show textual diff of current changes:� �g i t d i f f� �

S. Rockel 12

Page 21: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

Basic Tasks (cont’d)Get the current repo status

Show current branch, changes, untracked files:� �g i t s tatus� �Show commit history:� �g i t log� �Show textual diff of current changes:� �g i t d i f f� �

S. Rockel 12

Page 22: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Commonly used Commands Git Version Control System

Basic Tasks (cont’d)Get the current repo status

Show current branch, changes, untracked files:� �g i t s tatus� �Show commit history:� �g i t log� �Show textual diff of current changes:� �g i t d i f f� �

S. Rockel 12

Page 23: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Branches Git Version Control System

OutlineIntroductionConfiguration

User SetupRepository Setup

Basic TasksCommonly used CommandsBranches

Special UsecasesGUITagsRemote Repositories

S. Rockel 13

Page 24: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Branches Git Version Control System

Branchesthere might be life besides the master

List available branches� �g i t branch [−a ]� �Create a new branch� �g i t branch $newbranch� �Switch to a new branch� �g i t checkout $newbranch� �

S. Rockel 14

Page 25: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Branches Git Version Control System

Branchesthere might be life besides the master

List available branches� �g i t branch [−a ]� �Create a new branch� �g i t branch $newbranch� �Switch to a new branch� �g i t checkout $newbranch� �

S. Rockel 14

Page 26: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Branches Git Version Control System

Branchesthere might be life besides the master

List available branches� �g i t branch [−a ]� �Create a new branch� �g i t branch $newbranch� �Switch to a new branch� �g i t checkout $newbranch� �

S. Rockel 14

Page 27: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Basic Tasks - Branches Git Version Control System

Branches (cont’d)

Delete a branch� �g i t branch −d|−D $newbranch� �

S. Rockel 15

Page 28: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - GUI Git Version Control System

OutlineIntroductionConfiguration

User SetupRepository Setup

Basic TasksCommonly used CommandsBranches

Special UsecasesGUITagsRemote Repositories

S. Rockel 16

Page 29: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - GUI Git Version Control System

Guinot needed but nice to have� �

g i t fetch [ $branch|−− a l l ]� �Display changes, prepare, execute commit� �g i t gui� �Show all commits, branches� �g i tk [−− a l l ]� �

S. Rockel 17

Page 30: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - GUI Git Version Control System

Guinot needed but nice to have� �

g i t fetch [ $branch|−− a l l ]� �Display changes, prepare, execute commit� �g i t gui� �Show all commits, branches� �g i tk [−− a l l ]� �

S. Rockel 17

Page 31: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - GUI Git Version Control System

Merge Tool

I normally not neededI Git automatic merge is quite efficientI if there are merge conflicts, a (system dependent, see Git

config) merge tool can be used:� �g i t mergetool� �

S. Rockel 18

Page 32: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - GUI Git Version Control System

Merge Branches

I Master branch MI Work branch A and BI merge A and B into M� �

g i t checkout M # switch to branch Mg i t merge A # merge A into Mg i t merge B # merge B into M� �

S. Rockel 19

Page 33: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - Tags Git Version Control System

OutlineIntroductionConfiguration

User SetupRepository Setup

Basic TasksCommonly used CommandsBranches

Special UsecasesGUITagsRemote Repositories

S. Rockel 20

Page 34: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - Tags Git Version Control System

Don’t forget the tags

I tag versions� �g i t tag v1 . 3� �I git pull / push does not take tags into account� �

g i t p u l l | fetch −−tagsg i t push −−tags� �

S. Rockel 21

Page 35: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - Tags Git Version Control System

Don’t forget the tags

I tag versions� �g i t tag v1 . 3� �I git pull / push does not take tags into account� �

g i t p u l l | fetch −−tagsg i t push −−tags� �

S. Rockel 21

Page 36: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - Remote Repositories Git Version Control System

OutlineIntroductionConfiguration

User SetupRepository Setup

Basic TasksCommonly used CommandsBranches

Special UsecasesGUITagsRemote Repositories

S. Rockel 22

Page 37: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - Remote Repositories Git Version Control System

Github

https://github.com

add remote repo� �g i t remote add o r i g i n $remoteRepo� �

S. Rockel 23

Page 38: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - Remote Repositories Git Version Control System

Github

https://github.com

add remote repo� �g i t remote add o r i g i n $remoteRepo� �

S. Rockel 23

Page 39: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Special Usecases - Remote Repositories Git Version Control System

SVN

I Working with a remote Subversion repository (but with gitlocally)� �

git −svn clone [ http locat ion of an svn repos i to ry ]� �I Now you can work with the checked out directory as though it

was a git repository

S. Rockel 24

Page 40: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Appendix Git Version Control System

Thank You!

Any questions?

S. Rockel 25

Page 41: IntroductiontotheGitVersionControlSystem · UniversitätHamburg MIN-Fakultät DepartmentInformatik GitVersionControlSystem IntroductiontotheGitVersionControlSystem Sebastian Rockel

Universität Hamburg

MIN-FakultätDepartment Informatik

Appendix - Further Reading Git Version Control System

Further Reading

I http://linux.yyz.us/git-howto.htmlI http://help.github.com/git-cheat-sheets

S. Rockel 26