Error:
Diff between two branches
git diff master..another_branch
List files changed between two branches
git diff --name-status master..another_branch
Log on one line
git log --pretty=oneline
Delete tag
git tag -d tag_name
Delete remote tag (old way)
git push origin :refs/tags/tag_name
Delete remote tag (new way)
git push origin --delete tag_name
Push all tags
git push --tags
List annotated tags
git tag -l -n1
Delete remote branch (old way)
git push origin :branch_name
Delete remote branch (new way)
git push origin --delete branch_name
List cached files
git ls-files --cached
List deleted files
git ls-files --deleted
List modified files
git ls-files --modified
List untracked files
git ls-files --others
List files with their statuses
git status --porcelain
Enable color output
git config --global color.ui auto
Disable color output
git config --global color.ui false
Identify whitespaces problem
git config --global core.whitespace trailing-space,space-before-tab,indent-with-non-tab
List last 10 user's commits
git log -10 --no-merges --author=user --pretty=oneline
git blame for range of lines
git blame -L 10,+10 README.markdown
Revert single file to previous commit
git checkout HEAD~1 README.markdown
Find common ancestor for two branches
git merge-base master another_branch
Commit file partially
git add -p file.c
Checkout last branch
git checkout -
Get a file from another branch without switching
git checkout another_branch -- file.c
View diff for staged files
git diff --staged
Edit last commit message
git commit --amend -m "New message"
Checkout remote branch
git checkout -b branchname remotes/origin/branchname
Remove untracked files from working copy
# First check what's going to be removed using git clean -n -d
git clean -f -d
Export sources as zip archive
git archive --prefix project/ --format zip --output ../project.zip master
Export sources as tar.gz archive
git archive --prefix project/ master | gzip - > ../project.tar.gz
Export sources as tar.bz2 archive
git archive --prefix project/ master | bzip2 - > ../project.tar.bz2
Add empty directory to git repo
touch emptydir/.gitkeep && git add emptydir/.gitkeep
Rename current branch
git branch -m newbranch
Rename branch
git branch -m oldbranch newbranch
Discard unstaged changes
git stash save --keep-index && git stash drop
Ignore file mode changes
git config --global core.fileMode false
List files in the commit
git diff-tree --no-commit-id --name-only -r abcdef
Change author of last commit
git commit --amend --author "Firstname Lastname <email@company.com>"
Remove file from the repository without deleting it locally
git rm --cached file.c
Change remote url
git remote set-url origin git://github.com/gonzoua/project
Grep committed code
git grep MyString $(git rev-list --all)
List of files changed between two commits
git diff --name-only HEAD~7 HEAD~1
List of files changed between two commits and their statuses
git diff --name-status HEAD~7 HEAD~1
List of branches containing certain commit
git branch -a --contains abdef
View history graph
git log --graph --oneline --all
View stashed changes
git diff stash@{0}^1 stash@{0}
View stashed file
git show stash@{0}:Editor/Document.h
Get current branch name
git rev-parse --abbrev-ref HEAD
Get commit count
git rev-list HEAD --count