Interactively stage changes in a file
git add -ip <file>
Create a new, remote tracking branch (without branching from a local branch)
git co -b somebranch upstream/somebranch
Push a local branch to a differently named remote branch
git push origin localbranch:remotebranch
Checkout a branch from a remote fork
git remote add user [email protected]:user/project.git
git fetch user
git co -b user/their-branch
git pull user their-branch
Pull from someone else's branch on github
git pull [email protected]:user/project.git remotebranch
Push back to someone else's branch on github
git push [email protected]:user/project.git localbranch:remotebranch
Cherry picking commits
git cherry-pick foo # Grab the last commit from the foo branch
git cherry-pick foo foo~1 # Grab the last two commits from foo
Pop an old stash
git stash pop stash@{X} # where X is the stash number
Rebasing & Conflicts (because I sometimes forget this).
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort"
Need to squash some commits? You do that with rebase
. See this handy guide.
Want to complete destroy your last few commits? (never do this if you've shared these commits)
git reset --hard HEAD~X # where X is the number of commits backwards
Prune remote branches. When you run git branch -a
and see references to remote branches (e.g. remotes/origin/deleted-branch
) that have been deleted up-stream, you can remove your local references to them with:
git remote prune origin # prune the remote named "origin"
Need to learn more?
git help