Git cheat sheet
Commands Sequence the curves indicate that the command on the right is usually executed after the command on the left. This gives an idea of the flow of commands someone usually does with Git.
CREATE
BROWSE
CHANGE
REVERT
UPDATE
BRANCH
init clone
Create
From existing data
Concepts Git Basics master origin HEAD HEAD^ HEAD~4 : default development branch : default upstream repository : current branch : parent of HEAD : the great-great grandparent of HEAD
status log show diff branch
reset checkout revert
pull fetch merge am
checkout branch
commit
COMMIT
push format-patch PUBLISH
cd ~/projects/myproject git init git add .
From existing repo
git clone ~/existing/repo ~/new/repo git clone git://host.org/project.git git clone ssh://you@host.org/proj.git
Show
Files changed in working directory
Revert git reset --hard
Return to the last committed state
!
you cannot undo a hard reset
git status git diff
Revert the last commit
Update
Fetch latest changes from origin
Publish
Commit all your local changes
Changes to tracked files What changed between $ID1 and $ID2
git revert HEAD
Creates a new commit
Revert specific commit
git fetch
(but this does not merge them).
git commit -a
Prepare a patch for other developers
git revert $id
Fix the last commit
Creates a new commit
Pull latest changes from origin
git diff $id1 $id2 git log
git pull
History of changes History of changes for file with diffs
git commit -a --amend
(does a fetch followed by a merge)
git format-patch origin git push
(after editing the broken files)
Apply a patch that some sent you
Push changes to origin
Checkout the $id version of a file
git am -3 patch.mbox
git log -p $file $dir/ec/tory/ git blame $file git show $id