Skip to content

Instantly share code, notes, and snippets.

@kamiro
Forked from fubar/cheatsheet.md
Last active August 29, 2015 14:08
Show Gist options
  • Save kamiro/3183d3b58dda921b22fe to your computer and use it in GitHub Desktop.
Save kamiro/3183d3b58dda921b22fe to your computer and use it in GitHub Desktop.

Branches

list branches
git branch [-a to include remote branches]

create branch [from master]
git checkout -b HS-1234 [master]

update master, rebase and push
git checkout master
git pull
git checkout HS-1234
git rebase master
git push -f origin HS-1234

(2-step merge from master)
git fetch
git merge origin/master

delete branch
local: git branch -D HS-1234
remote: git push origin --delete HS-1234

rename branch
git branch -m HS-4321

Undo

undo git add (unstage)
git reset file.txt

revert changes
git checkout file.txt

Stash

stash and un-stash
git stash
git stash pop
git stash list

show diff of a stash
git stash show -p stash@{0}

remove most recent stash
git stash drop

Patches

apply a single commit (cherry-picking)
git cherry-pick a1b2c3

create and apply diff file
git diff COMMIT1 COMMIT2 > diff.patch
git apply --stat diff.patch
git apply --check diff.patch
git apply diff.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment