Git cheat sheet

2012-01-04 01:13:52

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:

Code:
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

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


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


Delete all merged branches (except those containing "master", for security, and the one you are currently on):
Code:
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):
Code:
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.
Code:
git fetch --prune origin