Kishore Vancheeshwaran
Git cheat sheet

Some commands I document to recall when necessary.

# Note: Any changes not committed will be lost.
git branch newbranch      # Create a new branch, saving the desired commits
git reset --hard HEAD~3   # Move master back by 3 commits (Make sure you know how many commits you need to go back)
git checkout newbranch    # Go to the new branch that still has the desired commits
git push -d <remote> <branch>
git branch -d <branch>
git fetch --all --prune # to get rid of branches on other machines. Note that this only removes the tracking and doesn't actually delete the branches locally
git branch -a # to view all branches
git branch -r # to view remote branches
git remote show origin
# the following deletes all local branches which aren't present. Use -D if it doesn't work. Usually that's because you have squashes and merges that's not present on local.
git fetch -p ; git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
git branch -vv
git remote show origin
git rebase -i HEAD~3 # to rebase 3 commits. See the devroom link for explanation
git rebase -i <after-this-commit> # pick/squash commits
git checkout <commit>
git checkout <branch>

Hope that helps

If you would like to leave a comment, contact me via email.
Post 21/99 - part of 100DaystoOffload