# File paternity test. Who is the author of the more lines, as returned by git blame. git blame FILE|cut -f 2 -d " "|sort|uniq -c|sort -rn|head -n 1 # Which .gitignore rule is ignoring a file git check-ignore -v filename # Highlight lines written at specific date when using git blame git blame README.md|ack --nogroup --passthru '.*(?:2017-05|2016).*?\)' # View commits since last tag git log --oneline --pretty=format:"%h%x09%an%x09%s" --no-merges `git describe --abbrev=0 --tags`..HEAD # To go 2 commits back git reset --hard HEAD~2 # To remove untracked files. Add '-x' to remove ignored files too. git clean -f -d # List all commits for a specific file git log --follow filename # View changes that are new on a feature branch git log -p feature --not master git diff master...feature # Interactive rebase for the last 7 commits (rewrite history) git rebase -i @~7 # Delete all remote branches that have been merged git branch -D $(git branch --merged | percol | awk '{print $1;}') # Move last n commits to a new branch # Note: Any changes not committed will be lost. # Note: newbranch must not exist beforehand! git branch newbranch # Create a new branch, saving the desired commits git reset --hard HEAD~3 # Move master back by 3 commits (GONE from master) git checkout newbranch # Go to the new branch that still has the desired commits # Revert merge commit git revert -m 1 # Search for a string in whole repository history git log -Spassword # Limit git log to commits specifics to the branch git log --first-parent --no-merges # Select git branches to delete interactively git branch -D $(git branch --merged | percol | awk '{print $1;}') # Rename current local branch git branch -m # Reset branch to origin remote version git reset --hard @{u} # @{u} is a shortcut for whatever your tracking branch is # Reset local changes git checkout -f