Spot an error? Know how to make this page better? I appreciate pull requests.

Git

Commands I always seem to forget

Push to multiple remotes with a single push.

git remote set-url --add --push <remote> <newurl>

Delete branch from remote.

# version >= 1.7.0
git push <remote> --delete <branch>

# version < 1.7.0
git push <remote> :<branch>

Add forgotten files to last commit.

git commit --amend -C HEAD

Decide last n commits should be on a different branch. Stackoverflow

git branch newbranch
# can also git reset --hard <hash>
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.
git checkout <newbranch>

Rewrap text to textwidth: gq


Checkout file from specific commit

git checkout <COMMIT> -- <path to file>