Git Configuration
Introduction
Git needs to know who you are when you create commits, and a few defaults make daily work smoother—default branch name, line endings, and your preferred editor. This chapter sets global configuration once on each machine; project-specific overrides come later.
Prerequisites
- Installing Git
git --versionworks in your terminal
Configuration Levels
Git reads settings from three places (last wins for same key):
| Level | File location | Scope |
|---|---|---|
| system | /etc/gitconfig (Linux) or installer path | All users on machine |
| global | ~/.gitconfig | Your user account |
| local | .git/config inside a repo | Single repository |
Learning track uses --global for identity and defaults.
git config --list --show-originCode explanation:
- Shows each setting and which file defined it—useful when something surprises you
Identity: name and email
Every commit records author metadata:
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"Code explanation:
- Use the name you want on GitHub and at work
- Email should match your Git hosting account if you want commit graph credit
Verify:
git config --global user.name
git config --global user.emailWarning
Use a Real Email for Public Work
Commits are public in open source. Use noreply GitHub email if you want privacy: id+username@users.noreply.github.com.
Default Branch Name
New repos use main by default on modern Git:
git config --global init.defaultBranch mainAvoids old master default on some legacy systems.
Choose an Editor for Commit Messages
When you run git commit without -m, Git opens an editor:
git config --global core.editor "code --wait"Examples:
| Editor | Setting |
|---|---|
| VS Code | "code --wait" |
| nano | "nano" |
| vim | "vim" |
Code explanation:
--waittells VS Code to block until you close the tab—required for Git integration
Line Endings (Important on Windows)
git config --global core.autocrlf trueOn macOS / Linux:
git config --global core.autocrlf inputCode explanation:
- Windows
true: checkout CRLF, commit LF—reduces “whole file changed” noise in mixed teams - Unix
input: checkout as-is, commit LF
Helpful Defaults
git config --global color.ui auto
git config --global pull.rebase false
git config --global push.default simpleCode explanation:
color.ui auto— coloredgit statusand diffs when terminal supports itpull.rebase false—git pullmerges (beginner-friendly default)push.default simple— push current branch to matching remote branch
Teams may override pull.rebase later.
View and Change Settings
git config --global --list
git config --global --unset core.editorEdit global file directly (optional):
# macOS / Linux
nano ~/.gitconfigExample ~/.gitconfig:
[user]
name = Ada Lovelace
email = ada@example.com
[init]
defaultBranch = main
[core]
editor = code --wait
autocrlf = input
[color]
ui = autoLocal Overrides (Preview)
Inside one repo only:
cd my-project
git config local.user.email "work@company.com"Use when personal global email differs from employer repo policy.
What Not to Put in Git Config
- Passwords, tokens, API keys—use credential helper or SSH keys (later chapter)
- Do not commit
.gitconfigwith secrets to dotfiles repo without review
Setup Checklist
-
user.nameanduser.emailset globally -
init.defaultBranch main -
core.editorset to an editor you know how to exit -
core.autocrlfappropriate for your OS -
git config --global --listlooks correct
FAQ
Forgot to configure before first commit?
Set config now; future commits use new identity—old commits keep old author unless rewritten (advanced).
Multiple GitHub accounts?
Use separate SSH keys and conditional includeIf in ~/.gitconfig—advanced topic; one account is enough for learning.
git config vs .gitconfig?
Same settings—CLI writes the file.
System config locked by IT?
Use --global only; you cannot change system level without admin.
Change name on old commits?
git rebase / filter-repo—only before sharing or with team agreement.
Where is global config on Windows?
C:\Users\<You>\.gitconfig