Git Cheat Sheet
by Jan Krger <jk@jk.gs>, http://jan-krueger.net/git/ Based on work by Zack Rusin
(left to right)
Command Flow
commit
commit
Basics
Use git help [command] if you're stuck. master origin HEAD HEAD^ HEAD~4 foo..bar default devel branch default upstream branch current branch parent of HEAD great-great grandparent of HEAD from branch foo to branch bar
create
init clone
browse
status log blame show diff
change
mark changes to be respected by commit:
revert
reset checkout revert
update
pull fetch merge am
branch
checkout branch
push
push
format-patch
add
Create
From existing files git init git add . From existing repository git clone ~/old ~/new git clone git://... git clone ssh://...
Publish
In Git, commit only respects changes that have been marked explicitly with add.
Useful Tools
git archive
Create release tarball
Tracking Files
git git git git add files mv old new rm files rm --cached files
(stop tracking but keep files in working dir)
git commit [-a]
(-a: add changed files automatically) (create set of diffs)
git format-patch origin git push remote git tag foo
(push to origin or remote) (mark current version)
git bisect
Binary search for defects
git cherry-pick
Take single commit from elsewhere
git fsck
Check tree
git gc
View
git git git git git git git git status diff [oldid newid] log [-p] [file|dir] blame file show id (meta data + diff) show id:file branch (shows list, * = current) tag -l (shows list)
Compress metadata (performance)
git rebase
Structure Overview
Local Repository working dir
checkout to switch commit commit
Update
git git git git git fetch (from def. upstream) fetch remote pull (= fetch & merge) am -3 patch.mbox apply patch.diff
git remote add URL git stash
Forward-port local changes to remote branch Register a new remote repository for this tree Temporarily set aside changes
git tag
(there's more to it)
gitk
Tk GUI for Git
Current Branch
(in .git)
Branch
(in .git)
Revert
In Git, revert usually describes a new commit that undoes previous commits.
Branch
git checkout branch
(switch working dir to branch)
Conflicts
Use add to mark files as resolved.
pull
push
git reset --hard (NO UNDO)
(reset to last commit)
git merge branch
(merge into current) (branch current) (branch new from other and switch to it)
git revert branch git commit -a --amend
(replaces prev. commit)
git branch branch
git checkout -b new other
git checkout id file
git diff [--base] git diff --ours git diff --theirs git log --merge gitk --merge
Remote repository (e.g. origin) Branch Branch