Git Notes
Git
List all branches (both local and remote)
?
1 git branch -a
List local branches and their corresponding upstream remote branches
?
1 git branch -vv
Revert local changes to a file (prior to commit)
?
1 git checkout file
Revert all local changes to the current subtree (prior to commit)
?
1 git checkout .
Cute hack to revert all local changes (prior to commit)
?
1 git stash git stash drop
Undo a commit
?
1 git reset --soft HEAD^
Undo multiple commits
?
1 git reset --soft HEAD@{2}
Where 2 is the number of commits to undo.
Update to latest HEAD, preserving local changes and local commits on
top
?
git stash
1
git pull --rebase
2 git stash pop
Push changes on master to origin
?
1 git push origin master
Delete untracked files and directories
?
1 git clean -df
Interactively stage patches from changed file(s)
?
1 git add -p <path>
Roll back the last commit's changes to a particular file
?
1 git checkout HEAD@{1} -- file
Branches
Branch master to a new local branch "new_branch"
?
1 git checkout -b new_branch master
Push local branch to remote
?
1 git push -u origin new_branch
Make the current local branch start tracking a corresponding remote
branch
?
1 git branch --set-upstream-to origin/new_branch
This is not necessary if you used git push -u as suggested above.
List the local branches that have already been merged to this one
?
1 git branch --merged
Diff a file between two branches
?
1 git diff branch1 branch2 -- file
Delete a branch both locally and remotely
?
1 git branch -rd origin/branch_to_kill
2 git branch -d branch_to_kill
3 git push origin :branch_to_kill