git config
Get and set Git settings
The 'git config' command reads and writes settings stored as key = value pairs. Without a scope it works on the current repository (.git/config); --global works on your user file (~/.gitconfig) and applies to every repository on your computer. A repository setting overrides the global one. The first settings everyone needs are user.name and user.email, which are stamped on each commit.
Synopsis
git config [--global | --local] <key> [<value>]
git config [--global] --unset <key>
git config [--global] --listOptions
Choosing the Right Option
Where settings live
The most specific one wins
| Command | File | Applies to |
|---|---|---|
--system | /etc/gitconfig | Every user of the computer |
--global | ~/.gitconfig | All your repositories |
--local (default) | .git/config | This repository only |
Examples
Set your name
git config --global user.name "Ada Lovelace"Used on every commit.
Set your email
git config --global user.email ada@example.comAlso used on every commit.
Read a setting
git config user.namePrints the value in effect here.
Default branch name
git config --global init.defaultBranch maingit init will start on main.
Workflow Examples
git config --global user.name "Ada Lovelace"Your name
git config --global user.email ada@example.comYour email
git config --global init.defaultBranch mainNew repositories start on main
Troubleshooting
Author identity unknown
Cause: user.name / user.email are not set
Set them with git config --global
A setting seems ignored
Cause: Another scope overrides it
git config --list --show-origin shows where each value comes from
Tips & Pitfalls
Best Practices
- ✓Set identity globally, override per repository only when needed (e.g. a work email).
- ✓Check settings with --show-origin when something behaves unexpectedly.
Common Mistakes
- ✗Committing before setting user.name and user.email.
- ✗Setting a work email with --global on a personal computer, or the opposite.
- ✗Quoting problems: names with spaces need quotes.
FAQ
~/.gitconfig (on Windows: C:\Users\<you>\.gitconfig).
git config --global core.editor "code --wait".