Git Config Cheat Sheet

Git configuration — global vs local settings, essential aliases, useful defaults, conditional includes, and productivity-boosting configuration.

Last Updated: May 1, 2025

Config Levels

LevelCommandFile LocationScope
Systemgit config --system/etc/gitconfigAll users on the machine
Globalgit config --global~/.gitconfigYour user account
Localgit config --localrepo/.git/configCurrent repository
Worktreegit configrepo/.git/config.worktreeCurrent worktree only

Essential Configuration

git config --global user.name Name
Set your name for all commits
git config --global user.email email
Set your email for all commits
git config --global core.editor code
Set editor (code, vim, nano, emacs)
git config --global init.defaultBranch main
Set default branch name
git config --global pull.rebase true
Always rebase on git pull
git config --global rebase.autosquash true
Auto-squash fixup!/squash! commits
git config --global push.default current
Push current branch to same-name remote
git config --global fetch.prune true
Auto-prune deleted remote branches on fetch

Productivity Aliases

git config --global alias.co checkout
git co = git checkout
git config --global alias.br branch
git br = git branch
git config --global alias.st status
git st = git status
git config --global alias.ci commit
git ci = git commit
git config --global alias.lg 'log --oneline --graph --all'
git lg = visual history
git config --global alias.unstage 'restore --staged'
git unstage file = unstage a file
git config --global alias.last 'log -1 HEAD'
git last = show the latest commit
git config --global alias.undo 'reset --soft HEAD~1'
git undo = undo last commit

Advanced Settings

git config --global core.autocrlf input
Handle line endings (input=LF on commit)
git config --global diff.tool vscode
Set default diff tool
git config --global merge.tool vscode
Set default merge tool
git config --global merge.conflictstyle diff3
Show base version in conflict markers
git config --global rerere.enabled true
Reuse recorded conflict resolutions
git config --global commit.verbose true
Show diff in commit message editor
git config --global includeIf 'gitdir:~/work/' .gitconfig-work
Conditional config by path
git config --list --show-origin
Show all config with file origins
Pro Tip: Set `git config --global pull.rebase true` — it makes your history cleaner and prevents unnecessary merge commits from `git pull`.