Git cheat sheet


Because... well, as awesome as people think git is, certain basic stuff are not that basic for git. Here's my collection because I'm getting tired of asking the same people for the same tricks over and over again :) Consider this a living document thingie...

Redirect a commit to a different branch:

git branch branch-name # copying the latest commit into separate branch
git reset HEAD^ # going one commit back
# git push origin -f # override it in the remote repository (only if already committed!)
git checkout branch-name # set branch-name as current branch
git push origin branch-name # push the local branch feature-filter to remote

Reintegrate branch

git checkout <branch-to-merge-into>
git pull
git merge <branch-to-reintegrate>
git pull

.gitconfig magic (default config and coloring):
name = Your Name
email =
ui = true
[color "diff"]
whitespace = red reverse

Delete all merged branches (except those containing "master", for security, and the one you are currently on):
git remote prune origin
// before i used this:
git branch | grep -v master | xargs -n 1 git branch -d

Compare committed changes in branch one to committed changes in branch two (so this ignores staged and unstaged):
git diff one...two
git diff master...bugfix

Remove old branch names from auto complete. (source) Pretty sure this won't affect anything else but take care.
git fetch --prune origin