Last Updated: May 1, 2025
Config Levels
| Level | Command | File Location | Scope |
|---|---|---|---|
| System | git config --system | /etc/gitconfig | All users on the machine |
| Global | git config --global | ~/.gitconfig | Your user account |
| Local | git config --local | repo/.git/config | Current repository |
| Worktree | git config | repo/.git/config.worktree | Current worktree only |
Essential Configuration
git config --global user.name NameSet your name for all commits
git config --global user.email emailSet your email for all commits
git config --global core.editor codeSet editor (code, vim, nano, emacs)
git config --global init.defaultBranch mainSet default branch name
git config --global pull.rebase trueAlways rebase on git pull
git config --global rebase.autosquash trueAuto-squash fixup!/squash! commits
git config --global push.default currentPush current branch to same-name remote
git config --global fetch.prune trueAuto-prune deleted remote branches on fetch
Productivity Aliases
git config --global alias.co checkoutgit co = git checkout
git config --global alias.br branchgit br = git branch
git config --global alias.st statusgit st = git status
git config --global alias.ci commitgit 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 inputHandle line endings (input=LF on commit)
git config --global diff.tool vscodeSet default diff tool
git config --global merge.tool vscodeSet default merge tool
git config --global merge.conflictstyle diff3Show base version in conflict markers
git config --global rerere.enabled trueReuse recorded conflict resolutions
git config --global commit.verbose trueShow diff in commit message editor
git config --global includeIf 'gitdir:~/work/' .gitconfig-workConditional config by path
git config --list --show-originShow 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`.