Skip to content

Instantly share code, notes, and snippets.

@knzm
Created March 3, 2012 10:31
Show Gist options
  • Save knzm/1965423 to your computer and use it in GitHub Desktop.
Save knzm/1965423 to your computer and use it in GitHub Desktop.
Git cheatsheet
How to get a remote branch on my local git repository:
$ git checkout origin/branch-1
$ git checkout -b branch-1
Or, is it a better way?
$ git checkout --track -b branch-1 origin/branch-1
How to add an upstream repository and get it:
$ git remote add upstream <url>
$ git fetch upstream
How to merge upstream changes into the 'master' branch in my forked repo:
$ git checkout master
$ git merge upstream/master
$ git push
How to cancel recent changesets:
(local)
$ git reset --hard <revision>
(github)
$ git push -f origin <revision>:<branch>
Misc commands I use frequently:
$ git push -v -n
$ git add -u
$ git commit -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment