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
change root of a branch
git rebase oldroot --onto newroot
update fork with upstream changes
git fetch upstream
git merge upstream/master
delete branch
local: git branch -D HS-1234
remote: git push origin --delete HS-1234
rename branch
git branch -m HS-4321
show repo origin URL (if referential integrity has been broken):
git config --get remote.origin.url
show repo origin URL (if referential integrity is intact):
git remote show origin
set remote repo URL
git remote set-url origin https://github.com/fubar/foo.git
list all remotes
git remote -v
remove remote
git remote rm origin
use a different certificate to authenticate with remote (current repo only):
git config http.sslKey ~/.ssh/my_other_id_rsa
Note: Don't forget to register a newly created key via:
ssh-add ~/.ssh/my_other_id_rsa
See https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
stage only tracked files
git add -u
undo git add (unstage)
git reset file.txt
revert changes
git checkout file.txt
undo last commit (back to stage)
git reset --soft HEAD~
stash and un-stash
git stash
git stash pop
git stash list
show diff of a stash
git stash show -p stash@{0}
apply a specific stash
git stash apply stash@{0}
remove most recent stash
git stash drop
remove all stashes
git stash clear
apply a single commit (cherry-picking)
git cherry-pick COMMITHASH
create and apply diff file
git diff COMMITHASH^ COMMITHASH > diff.patch
git apply --stat diff.patch
git apply --check diff.patch
git apply diff.patch
diff a single commit
git diff COMMITHASH^ COMMITHASH
diff between two commits
git diff COMMITHASH1 COMMITHASH2
view a single commit with commit message
git show COMMITHASH
show unstaged, uncommitted changes
git diff
show staged changes
git diff --cached
show staged and uncommitted changes
git diff HEAD
for more details, see http://stackoverflow.com/a/1587952/5339584
simple list of commits between two hashes/tags
git log FOO..BAR --oneline --no-merges