Setup and Config
Remove sensitive data from history, after a push
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <path-to-your-file>' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all
Reset author, after author has been changed in the global config.
git commit --amend --reset-author --no-edit
Get git bash completion
curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc
Git Aliases
git config --global alias.<handle> <command>
git config --global alias.st status
Always rebase instead of merge on pull.
git config --global pull.rebase true
Alternatives:
#git < 1.7.9
git config --global branch.autosetuprebase always
List all the alias and configs.
git config --list
Make git case sensitive.
git config --global core.ignorecase false
Add custom editors.
git config --global core.editor '$EDITOR'
Auto correct typos.
git config --global help.autocorrect 1
Reuse recorded resolution, record and reuse previous conflicts resolutions.
git config --global rerere.enabled 1
Remove entry in the global config.
git config --global --unset <entry-name>
Ignore file mode changes on commits
git config core.fileMode false
Turn off git colored terminal output
git config --global color.ui false
Specific color settings
git config --global <specific command e.g branch, diff> <true, false or always>
Alias: git undo
git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'
Edit [local/global] git config
git config [--global] --edit
List all git aliases
git config -l | grep alias | sed 's/^alias\.//g'
Alternatives:
git config -l | grep alias | cut -d '.' -f 2
Use SSH instead of HTTPs for remotes
git config --global url.'git@github.com:'.insteadOf 'https://github.com/'
Prevent auto replacing LF with CRLF
git config --global core.autocrlf false
Edit config for each level
git config --edit --system
git config --edit --global
git config --edit --local