Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Source Code Management wih git
Matthieu Herrb
December 2012
httphomepageslaasfrmatthieucoursgitpdf
Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 30 UnportedLicenseTo get a copy of the license use the following addresshttpcreativecommonsorglicensesby-sa30
Parts of this document have been re-used and translated from Johan Moreau laquo Outilsde construction raquo et de Konrad Hinsen laquo Packaging en Python raquo for the ENVOL 2010CNRS school
December 2012 254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 354
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 454
Introduction
Distributed version control systemby opposition to CVS or SVN which are CentralizedDevelopped by Linus Torvalds for the Linux kernelSimilar to Monotone Darcs Mercurial Bazaar etc
December 2012 554
Version Control concepts (1)
RepositoryDirectory or other form of storage keeps the history ofmodificationsRevisionEach state of the source files has a unique identifierrarr revisionAlso called commit as language shortcut
A B C
Sorted sequencerarr Marketing project version 6= VCS revision
December 2012 654
Version Contol concepts (2)
Branches
A B C D I J
E F
G
H K
December 2012 754
Handling branches
Branches can be used for fixing a bug in an released versiondevelop new ideas in parallelmanage a customized version of the softwaremerge back a version that diverged for some reasontrack local modifications to externally maintained sources
December 2012 854
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Licence
This work is licensed under a Creative Commons Attribution-ShareAlike 30 UnportedLicenseTo get a copy of the license use the following addresshttpcreativecommonsorglicensesby-sa30
Parts of this document have been re-used and translated from Johan Moreau laquo Outilsde construction raquo et de Konrad Hinsen laquo Packaging en Python raquo for the ENVOL 2010CNRS school
December 2012 254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 354
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 454
Introduction
Distributed version control systemby opposition to CVS or SVN which are CentralizedDevelopped by Linus Torvalds for the Linux kernelSimilar to Monotone Darcs Mercurial Bazaar etc
December 2012 554
Version Control concepts (1)
RepositoryDirectory or other form of storage keeps the history ofmodificationsRevisionEach state of the source files has a unique identifierrarr revisionAlso called commit as language shortcut
A B C
Sorted sequencerarr Marketing project version 6= VCS revision
December 2012 654
Version Contol concepts (2)
Branches
A B C D I J
E F
G
H K
December 2012 754
Handling branches
Branches can be used for fixing a bug in an released versiondevelop new ideas in parallelmanage a customized version of the softwaremerge back a version that diverged for some reasontrack local modifications to externally maintained sources
December 2012 854
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 354
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 454
Introduction
Distributed version control systemby opposition to CVS or SVN which are CentralizedDevelopped by Linus Torvalds for the Linux kernelSimilar to Monotone Darcs Mercurial Bazaar etc
December 2012 554
Version Control concepts (1)
RepositoryDirectory or other form of storage keeps the history ofmodificationsRevisionEach state of the source files has a unique identifierrarr revisionAlso called commit as language shortcut
A B C
Sorted sequencerarr Marketing project version 6= VCS revision
December 2012 654
Version Contol concepts (2)
Branches
A B C D I J
E F
G
H K
December 2012 754
Handling branches
Branches can be used for fixing a bug in an released versiondevelop new ideas in parallelmanage a customized version of the softwaremerge back a version that diverged for some reasontrack local modifications to externally maintained sources
December 2012 854
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 454
Introduction
Distributed version control systemby opposition to CVS or SVN which are CentralizedDevelopped by Linus Torvalds for the Linux kernelSimilar to Monotone Darcs Mercurial Bazaar etc
December 2012 554
Version Control concepts (1)
RepositoryDirectory or other form of storage keeps the history ofmodificationsRevisionEach state of the source files has a unique identifierrarr revisionAlso called commit as language shortcut
A B C
Sorted sequencerarr Marketing project version 6= VCS revision
December 2012 654
Version Contol concepts (2)
Branches
A B C D I J
E F
G
H K
December 2012 754
Handling branches
Branches can be used for fixing a bug in an released versiondevelop new ideas in parallelmanage a customized version of the softwaremerge back a version that diverged for some reasontrack local modifications to externally maintained sources
December 2012 854
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Introduction
Distributed version control systemby opposition to CVS or SVN which are CentralizedDevelopped by Linus Torvalds for the Linux kernelSimilar to Monotone Darcs Mercurial Bazaar etc
December 2012 554
Version Control concepts (1)
RepositoryDirectory or other form of storage keeps the history ofmodificationsRevisionEach state of the source files has a unique identifierrarr revisionAlso called commit as language shortcut
A B C
Sorted sequencerarr Marketing project version 6= VCS revision
December 2012 654
Version Contol concepts (2)
Branches
A B C D I J
E F
G
H K
December 2012 754
Handling branches
Branches can be used for fixing a bug in an released versiondevelop new ideas in parallelmanage a customized version of the softwaremerge back a version that diverged for some reasontrack local modifications to externally maintained sources
December 2012 854
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Version Control concepts (1)
RepositoryDirectory or other form of storage keeps the history ofmodificationsRevisionEach state of the source files has a unique identifierrarr revisionAlso called commit as language shortcut
A B C
Sorted sequencerarr Marketing project version 6= VCS revision
December 2012 654
Version Contol concepts (2)
Branches
A B C D I J
E F
G
H K
December 2012 754
Handling branches
Branches can be used for fixing a bug in an released versiondevelop new ideas in parallelmanage a customized version of the softwaremerge back a version that diverged for some reasontrack local modifications to externally maintained sources
December 2012 854
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Version Contol concepts (2)
Branches
A B C D I J
E F
G
H K
December 2012 754
Handling branches
Branches can be used for fixing a bug in an released versiondevelop new ideas in parallelmanage a customized version of the softwaremerge back a version that diverged for some reasontrack local modifications to externally maintained sources
December 2012 854
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Handling branches
Branches can be used for fixing a bug in an released versiondevelop new ideas in parallelmanage a customized version of the softwaremerge back a version that diverged for some reasontrack local modifications to externally maintained sources
December 2012 854
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Working in teams
No locks on source codeEach developper has its own copy of the source and repositoryConflicts handling
First merge other peoplersquos contributionAutomated merges as much as possibleConflict detection rarr manual resolutionNo new commit before solving the conflict
December 2012 954
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Centralized model
Pull
Pull
Push
Anne
Bernard Carole
Denis
Central repository
PullPull
Push
December 2012 1054
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Distributed model
Commit
Commit
pull
pushpull
Geacuterard
pull
push
pull
Fabienne
Commit
pullHeacutelegravene
Eric
December 2012 1154
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1254
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Git concepts (1)
repository all the history of the projectstored in the git directory
diff or patch differences between 2 versions of a filecommit (verb) action to register a version of a set of files
to the repositorycommit (noun) the result of a commit action represented by
a 128 hexadecimal SHA-1 hashbranch one line of development
by default all development is done in mastertag a symbolic identifier for a commit or a branch
December 2012 1354
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Git concepts (2)
Working tree the set of files being worked on currentlyIndex an object tracking modified added removed filesBlob binary data used to store files objects and other data
December 2012 1454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Git Interfaces
Command lineGit GUIs
gitk git-gui (part of git distribution)git-cola httpgit-colagithubcomTortoiseGit (Windows)httpcodegooglecomptortoisegit
Eclipse plugin (httpeclipseorgegit)Web browsers cgit gitweb
December 2012 1554
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Git forges
Web sites dedicated to git projects hostinggitorious httpgitoriousorg
github httpsgithubcom
Include interesting features for collaboration
Better suited for distributed developement than traditionalcentralized forges
December 2012 1654
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Initial setup
Sets defaults for commit messagesuser name amp emailpreferred text editor
git config --global --add username Matthieu Herrb git config --global --add useremail
ltmatthieuherrblaasfrgt git config --global --add coreeditor emacs -nw cat ~gitconfig[user]
name = Matthieu Herrbemail = ltmatthieuherrblaasfrgt
[core]editor = emacs -nw
December 2012 1754
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 1854
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Creating a repository
git init creates an empty repository in the current directory mkdir git-tutorial cd git-tutorial git initInitialized empty Git repository in homemhgit-tuturialgit ls -l gittotal 24-rw-r--r-- 1 mh mh 23 Oct 26 0914 HEAD-rw-r--r-- 1 mh mh 111 Oct 26 0914 config-rw-r--r-- 1 mh mh 58 Oct 26 0914 descriptiondrwxr-xr-x 12 mh mh 408 Oct 26 0914 hooksdrwxr-xr-x 3 mh mh 102 Oct 26 0914 infodrwxr-xr-x 4 mh mh 136 Oct 26 0914 objectsdrwxr-xr-x 4 mh mh 136 Oct 26 0914 refs
December 2012 1954
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Adding files
git add adds new or modified files to the index echo Hello World gt filetxt git add
December 2012 2054
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Querying status
Shows the status of the repository and the index
git status On branch master Initial commit Changes to be committed (use git rm --cached ltfilegt to unstage) new file filetxt
December 2012 2154
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Committing changes
git commitCreated initial commit 0ba7bd8 Initial version1 files changed 1 insertions(+) 0 deletions(-)create mode 100644 filetxt
echo Hello Matthieu gt filetxt git commit -aCreated commit 7fbf4cb Modif1 files changed 1 insertions(+) 1 deletions(-)
Opens a text editor to enter a commit messageand commits the change to the repository
December 2012 2254
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
The git index
Represents modifications pending commit2 stages
1 add modified files to the index (addrm)2 ldquoflushrdquo the index to the repository (commit)
Short-cuts chaining both operationsgit commit file
git commit dir (or git commit )git commit -a
December 2012 2354
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Commits
Adds a node at the end of the current branch
A B C
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Commits
Adds a node at the end of the current branch
A B C D
Includesthe patch from old to new revision for text filesthe full new revision for binary filesattributes of the commited file (access modes)name and e-mail address of the committera log messageoptionnally a digital signature
December 2012 2454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Interactive add
git add -i [files]
Enters an interactive session to pick up changes to be added tonext commit
Allows to have several unrelated un-committed modifications andstill do clean separate commits
December 2012 2554
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Looking back
Various ways to display the history of modifications git logcommit 7fbf4cb7c8977061fbfb609016f5414e833a3a1cAuthor Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122933 2008 +0100
Modif
commit 0ba7bd8b93ef9ddd8917814bde8cbdaaf9732559Author Matthieu Herrb ltmatthieuherrblaasfrgtDate Tue Oct 28 122838 2008 +0100
Initial version git log --stat git log -p
December 2012 2654
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Examining changes
Display the changes between the working files and the indexor between the index and the repositoryecho Good bye gt filetxt git diffdiff --git afiletxt bfiletxtindex 6bd8f3cc0ee9ab 100644--- afiletxt+++ bfiletxt -1 +1 -Hello Matthieu+Good bye git add filetxt git diff --cached
December 2012 2754
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Marking a version
Create a tag object containing a name and a commentOpens the text editor to ender the comment git tag -a git-tuto-10 git tag -lgit-tuto-10
December 2012 2854
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Fixing mistakes reverting to a good version
Restore the working dir to a given committed versionloosing all local changes git reset --hard [commit-id]
If commit-id is missing defaults to HEAD
Revert a given commit git revert 03baceFinished one revertCreated commit c333ab5 Revert 3rd version1 files changed 1 insertions(+) 1 deletions(-)
December 2012 2954
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 3054
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
Existing history
Branch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
D
Existing historyBranch creation
commits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
D E
Existing historyBranch creationcommits in the new branch
commits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
D E
F
Existing historyBranch creationcommits in the new branchcommits in master
merge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
D E
F G
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into master
further commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
D E
F G
H
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branch
etc
December 2012 3154
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
D E
F G
H I
J
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
D E
F G
H I
J K
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Branches
A B C
D E
F G
H I
J K
L
Existing historyBranch creationcommits in the new branchcommits in mastermerge the branch into masterfurther commits in the branchetc
December 2012 3154
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Switching branches
Create a new branch git checkout -b newbranch
Switch back to master git checkout master
December 2012 3254
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Listing available branches
git branch master
newbranch
December 2012 3354
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Merging changes from another branch
git merge branch
Merge commits from ldquobranchrdquo and commits the result
2 kinds of mergesfast forward no conflicts only new commits to add to yourversionnormal merge there are local changes - use a 3 way mergealgorithm
December 2012 3454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Handling conflicts
Conflicts happen when changes in a merged branch areincompatible with changes in the target branch
Files with conflicts contain conflict markersThey are not automatically added to the indexResolve the conflictAdd the files to the indexCommit the result
December 2012 3554
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Tools to help with merge
To help solving conflictsgit can use existing tools to help merging kdiff3 tkdiff meldxxdiff opendiff git config --global mergetool meld
git mergetool
December 2012 3654
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Picking individual changes
Take one commit from another branch (bug fix)and apply it to the working branch
git cherry-pick SHA1_HASH
December 2012 3754
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Replaying changes from a branch
Merges create lots of unwanted links in the git data graphWhen a branch has only few local commits rebase is moreefficient
git rebase master
December 2012 3854
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Rebase
A B
Existing commits
Development branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Rebase
A B
C D E
Existing commitsDevelopment branch
Commits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Rebase
A B
C D E
F G
Existing commitsDevelopment branchCommits in master
Start of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Rebase
A B F G
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branch
End of rebase recreate commits starting from HEAD demaster
December 2012 3954
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Rebase
A B F G
Crsquo Drsquo Ersquo
Existing commitsDevelopment branchCommits in masterStart of rebase remove commits from the branchEnd of rebase recreate commits starting from HEAD demaster
December 2012 3954
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Interactive rebase
Useful to re-arrange commits locally in order to clean up thehistory git rebase -i COMMITS
rarr opens a text editor with the list of commits specifiedRearrange the list according to instructions and save itrarr history will be re-written following the new list
Donrsquot use that afer pushing your commits
December 2012 4054
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4154
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Copying a repository
git clone repo
repo an url to the remote repository Can bea pathname to a local repository on the same filesystemssh[user]hostpath - use SSH with given usergithostpath - anonymous acces with the GIT protocolhttphostpath - anonymous acces with HTTP protocol
December 2012 4254
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Remote repository
Remote repo A B C D master
December 2012 4354
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Remote repository
Remote repo A B C D master
Local repo A B C D originmaster
master
clone
December 2012 4354
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Updating from a repository
git pull
Pulls the remote branches to the local repositorymerges the default remote branch into the current one(Including commit)Can produce a conflict
Solve the conflictCommit the result
December 2012 4454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Remote branches
git branch -r
lists remote branches (originbranch)
Remote branches can be tracked (automatically mergedpushed)using git checkout -t -b newbranch originnewbranch
December 2012 4554
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Using rebase with remote branches
fecth fetches remote commits without merging them git fetch
Fetch and rebase at once git pull --rebase
equivalent to git fetch git rebase originmaster
December 2012 4654
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Sending changes to a repository
git push
Sends local commits to remote tracked branchesProduces an error if not up-to-date (need to pull or rebase first)
Tags need to be pushed separatly git push --tags
December 2012 4754
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Managing remote repositories
git remote command
add name url add a remoteset-url name url changes the urlrename old new renamesrm name removes a remote
December 2012 4854
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 4954
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Identifying authors
git blame -- filetxt
for each line of the file shows the id and author of the lastmodification
December 2012 5054
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Making a relase with git
(Alternative to automakersquos make dist)Commit all changes including the new macro revision numberTag the resultUse archive to produce a release
git tag -a foo-13 git archive --prefix=foo-13 foo-13
| gzip -c - gt foo-13targz
December 2012 5154
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Submodules
Submodules provide a way to glue several existing repositories intoa bigger project
git submodule add url pathadds a submodule at pathgit submodule initinit the sub-modulesgit submodule updateclone or pull the submodulesgit submodule statusdisplay information about submodule status
December 2012 5254
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Agenda
1 Introduction
2 Git concepts
3 Individual developper
4 Using branches
5 Working together
6 Other goodies
7 Appendix
December 2012 5354
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454
Git for CVS users
CVS gitcheckout cloneupdate pullcommit commit -a + pushadd addremove rmdiff difflog log
December 2012 5454