I’ve been slowly adding to a cheat sheet I printed out a year ago. Half the commands I don’t use and the ones I use the most aren’t on there, so here’s mine…
Check out a new repo
git clone git://location/proj.git
Actually see what’s going on
gitk --all
Interactive adding for commits
git add -i
Unstage changes
git reset HEAD
Return to last committed state
git reset --hard
Undo a merge
git reset --hard [ID]
git reset --hard HEAD~[number back]
Undo a commit with message
git reset --soft HEAD^
Modify a commit
git commit --amend
Add more files to existing commit
git add ...
git commit --amend -C HEAD
Branches have diverged – just get up stream
git reset --hard @{upstream}
Checkout specific version of a file
git checkout [ID] [FILE]
Updating submodules
git submodule init
git submodule sync
git submodule update
Go through every submodule and checkout the head
git submodule foreach git checkout master
git submodule foreach git pull origin master
Or automatically merge
git submodule update --merge
Show difference between two branches
git diff [BRANCH 1]..[BRANCH 2]
Difference between two commits
git diff [ID1] [ID2]
Merge a branch back into master
git checkout master
git merge [BRANCH]
Show all branches
git branch --all
Checkout and track remote branch
git checkout -t [BRANCH]