Where the settings live
| Level | File | Command |
|---|---|---|
| system | /etc/gitconfig; for Git for Windows, etc/gitconfig in the install directory |
git config --system |
| user | ~/.gitconfig or ~/.config/git/config |
git config --global |
| repository | .git/config |
git config inside the repository |
They’re read in order, and the last value wins: a repository setting overrides the global one. Where a value came
from: git config --show-origin --get <name>.
Git for Windows already writes core.autocrlf=true into the system file — you can see it in git config --system --list.
Override it in your own file (the last block).
The file, block by block
[user]
name = example-user
email = [email protected]Without a name and email git won’t create a commit. Use the …@users.noreply.github.com address from your GitHub settings if you don’t want to show your personal one (Git from scratch).
[init]
defaultBranch = mainA new repository’s first branch is main, as on GitHub. Without this line git 2.x calls it master and shows a hint.
default master
[pull]
rebase = true
[rebase]
autoStash = trueWhen your branch and origin diverge, pull moves your commits on top of theirs instead of making a “Merge branch 'main' of github.com:…” commit. History stays linear. Without the setting, git since 2.33 refuses: fatal: Need to specify how to reconcile divergent branches. autoStash puts uncommitted edits aside for the rebase and brings them back on its own.
default:rebase unset — an error on divergenceautoStash false
[push]
autoSetupRemote = true
[fetch]
prune = trueThe first git push of a new branch creates it on origin and links it — no --set-upstream origin name (git 2.37+). prune removes origin/… branches deleted on GitHub on fetch; otherwise the list grows for years.
default:autoSetupRemote falseprune false
[merge]
conflictStyle = zdiff3A conflict shows three versions: yours, theirs, and the common ancestor between ||||||| and =======. The ancestor shows who changed what: it was port: 80, yours became 9090, theirs 8080. Without it you see only two versions and can’t tell whose edit is newer (Branches in git). zdiff3 needs git 2.35.
default merge — two versions
[rerere]
enabled = true
[diff]
algorithm = histogram
colorMoved = defaultrerere remembers how you resolved a conflict and resolves the same conflict itself next time — on a repeated rebase. histogram is a diff algorithm that confuses moved blocks less often; colorMoved colors moved lines separately.
default:rerere.enabled falsediff.algorithm myers
[core]
editor = code --waitThe editor for commit and rebase messages. --wait is required: without it VS Code returns control right away, and git sees an empty message. On a server, nano or vim.
default vi or $EDITOR
autocrlf = falseLeave line endings alone: what’s in the file is what goes into the repository. Rules for specific files belong in .gitattributes in the repository itself, which travels with it to every computer (Line endings in .gitattributes). This line overrides the core.autocrlf=true that Git for Windows writes into the system config.
default true on Git for Windows, false on Linux and macOS
[branch]
sort = -committerdate
[tag]
sort = version:refname
[column]
ui = autoList order: branches newest first, tags by version number (v1.10 after v1.9), lists in columns.
default:branch.sort by nametag.sort alphabetical
[alias]
lg = log --oneline --graph --decorate --all -20
st = status -sb
last = show --stat HEADShort commands. git lg is a graph of the last 20 commits on every branch; git st a two-column status with the branch; git last what’s in the last commit.
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-workA different email for work repositories: everything under ~/work/ also takes settings from ~/.gitconfig-work. The trailing slash is required — otherwise only the directory itself matches.
[gpg]
format = ssh
[commit]
gpgSign = trueSigning commits with an SSH key — the same one you log in with. GitHub marks such commits “Verified”. The setup and the signing key — Git and SSH keys.
default unsigned
If it doesn’t work
A setting in ~/.gitconfig has no effect in one repository
- Cause
- The repository’s
.git/configoverrides it — it’s read later and wins. - Fix
git config --show-origin --get pull.rebaseshows which file the value came from.
On Windows git config --global writes somewhere other than the file you have open
- Cause
- Git for Windows’
HOMEisn’t alwaysC:\Users\<name>; portable git has its own. - Fix
git config --global --list --show-origin | head -1gives the path of the file git edits.
includeIf doesn’t pick up the work settings
- Cause
- A
gitdir:path without a trailing slash matches only the directory itself, not the repositories inside; on Windows, letter case differs. - Fix
- Write
gitdir:~/work/with the slash; on Windows usegitdir/i:for case-insensitive matching.
How to check
What’s in effect and where it comes from:
git config --global --list --show-origin | head -5
# file:/home/me/.gitconfig user.name=example-user
# file:/home/me/.gitconfig [email protected]
# file:/home/me/.gitconfig init.defaultbranch=main
# file:/home/me/.gitconfig pull.rebase=true
# file:/home/me/.gitconfig rebase.autostash=true
git config --show-origin --get core.autocrlf
# file:/home/me/.gitconfig false
A conflict now shows the common ancestor — the output has a ||||||| line:
name: site
<<<<<<< HEAD
port: 9090
||||||| 217e8ca
port: 80
=======
port: 8080
>>>>>>> feature
workers: 2