Git cheat sheet

Creating a branch

git branch branch_name

Can then be pushed upstream with

git push

Or to push up and set as upstream in one step

git push -u origin branch_name

To track upstream changes on existing local branch

git branch --set-upstream origin branch_name

To pull a branch down and track

git branch -t branch_name origin/branch_name

Merge to master branch

git checkout master
git merge branch_name

Delete the remote branch (weird syntax with the “:”!)

git push origin :branch_name

And delete local branch

git branch -d branch_name

Get last pulled down changes
Here ORIG_HEAD refers to the previous HEAD

git diff --name-status ORIG_HEAD..

And the log messages associated with the changes

git log ORIG_HEAD..

Stash particular files

  • Stage the files that you want to keep modified
    git add 
  • Stash the files you want to revert
    git stash --keep-index
  • The file changes can be recovered by
    git stash apply