12/23/2016 - 1:33 PM

# Reset/checkout a single file from remote origin `branch`
git fetch --all
git checkout origin/branch -- path/to/file

# Reset local repository branch to be just like remote repository HEAD
git fetch origin && git reset --hard origin/develop

# Update current branch from dev
# `git checkout dev; git pull origin dev; git checkout branch; git rebase dev`
git pull --rebase origin develop
git pull --rebase origin stage

# Update current branch from dev when there're uncommited changes
git stash && git pull --rebase origin develop && git stash apply

# Delete a local branch
git branch -d the_local_branch

# Remove a remote branch
git push origin :BRANCH

# New branch with local unstaged changes in the working directory
git checkout -b experiment

# How to remove a file from git source control but not delete it
git rm --cached file

# Stashing
git stash # = `git stash save` record the current state of the working directory
git stash list # list stashed modifications
git stash apply # restore (potentially on top of a different commit)

# Delete the last pushed commit
git push origin +hash^:BRANCH

# Set upstream branch
git branch BRANCH -u origin/BRANCH

# Revert repository to a commit
git revert --no-commit hash..HEAD
git commit

# Remove local branches except for "master"
git branch | grep -v "master" | xargs git branch -D