list all (local + remote) branches
$ git branch -a
create local tracking branches for all remote branches
gitbash $ for remote in `git branch -r `; do git branch --track $remote; done
register submodule, pull from repo
git submodule add url_to_repo
delete submodule
git rm --cached path_to_submodule
set username globally
git config --global user.name "david.barkhuizen@gmail.com"
set username for repo
git config remote.origin.url https://user_name@repo
edit remote url
git remote set-url origin git://new.url.here
list remotes
git remote -v
fetch all remote branches
$ git fetch --all
fetch remote branch xxx, anx create local tracking branch xxx
git checkout --track origin/xxx
fetch all remote branches, NOT creating local branches tracking respective remotes
git fetch --all
pull (fetch and merges) remote branches for all existing local branches
git pull --all
fetch all branches from remote origin
git fetch origin
fetch branch xxx from remote origin, and create local branch with same name
git fetch origin xxx:xxx
set local branch to track remote with same name
git push --set-upstream origin xxx
fetch all remote branches, and create local branch xxx tracking remote branch xxx
git fetch && git checkout xxx
switch to local branch xxx
git checkout xxx
create new local branch xxx, keeping uncommitted changes
git checkout -b xxx
create new local branch xxx, from commit yyy
git checkout -b xxx yyy
rename local branch old_name to new_name
git branch -m old_name new_name
list local tags
git tag
git tag -l
create annotated tag with name xxx and description yyy
git tag -a xxx -m yyy
create annotated tag with name xxx and description yyy, from commit with SHA hash hash
git tag -a xxx hash -m yyy
create lightweight tag named xxx
git tag xxx
push local tags to remote repo
git push origin --tags
get revision detail for tag xxx
git rev-list -1 xxx
checkout tag xxx
git checkout tags/xxx
delete local tag xxx
git tag -d xxx
delete remote tag xxx
git push --delete origin xxx
push all local branches to remote, configuring tracking
git push --all -u
merge a specific commit with hash xxx from another branch into the current one
git cherry-pick xxx
undo last merge before pushing (assuming no other changes)
git reset --merge ORIG_HEAD
overwrite the deploy_to_SIT branch with an existing branch, xxx
git checkout deploy_to_SIT
git reset --hard xxx
git push origin --force
accept all incoming changes during rebase
git rebase -X theirs origin/master
create changes (but do not commit them) that will revert to revision with hash
git revert --no-commit <commit-id> -n HEAD
revert a single file @ xxx/y.js to its state in revision with hash rev_hash_zzz
git checkout rev_hash_zzz xxx/y.js
temporarily revert repo to previous commit xxx, leaving head in detached state
git checkout xxx
revert to commit xxx, permanently discarding all subsequent unpublished commits
git reset --hard xxx
revert to commit xxx, retaining all changes
git reset xxx
diff two branches - branch_x, branch_y
git diff branch_x branch_y
print hash of last commit
git rev-parse HEAD
print last commit message
git log -1