git config
Beginner Git CLI Safe
Summary: git config <key> <value> writes a setting; git config <key> reads it; --global targets your user-wide file, no flag targets the current repository, --system the machine.
Safe — settings affect future commands only; nothing in history or in your files changes. A wrong value is fixed by setting it again or unsetting it.
What it does
Edits one of three plain-text INI files (/etc/gitconfig, ~/.gitconfig, .git/config) or reads them with the precedence local > global > system.
Why it exists
Git needs to know who you are, which editor to open, how to handle line endings and remotes, and a hundred optional preferences; all of it lives in these files.
When to use it
- First-time setup: identity, default branch, editor, credential helper (lesson 3.3).
- A per-project override (a different email for one repository).
- Diagnosing "why does Git do that?" with
--list --show-origin. - Aliases for long commands.
When not to use it
- For ignore rules (
.gitignore) or attributes (.gitattributes): those are files in the repository so that the team shares them. - To store secrets: never put tokens or passwords in a config value.
Syntax
| Form | Meaning |
|---|---|
git config --global <key> "<value>" |
Set for all your repositories |
git config <key> "<value>" |
Set for this repository only |
git config <key> |
Read the effective value |
git config --global <key> |
Read the global value only |
git config --list |
All effective settings |
git config --list --show-origin |
…with the file each comes from |
git config --global --unset <key> |
Remove a setting |
git config --global --edit |
Open the file in your editor |
git config --global alias.<name> "<git subcommand>" |
Define a shortcut |
Keys are section.name, case-insensitive: user.email, init.defaultBranch, core.editor, core.autocrlf, pull.rebase, push.autoSetupRemote, fetch.prune, credential.helper, merge.conflictstyle.
Examples
$ git config --global user.name "Ana Lopez"
$ git config --global user.email "ana@northwind-trails.example"
$ git config --global init.defaultBranch main
$ git config --global --listuser.name=Ana Lopez
user.email=ana@northwind-trails.example
init.defaultbranch=main
core.editor=code --wait
pull.rebase=false
push.autosetupremote=true$ git config user.email "ana@personal.example"
$ git config user.emailana@personal.example$ git config --global user.emailana@northwind-trails.example
Where a value comes from:
$ git config --list --show-originfile:/Users/you/.gitconfig user.name=Ana Lopez
file:/Users/you/.gitconfig user.email=ana@northwind-trails.example
file:.git/config core.repositoryformatversion=0
file:.git/config core.bare=false(Abbreviated; system-level lines appear first.) The global file itself:
[user]
name = Ana Lopez
email = ana@northwind-trails.example
[init]
defaultBranch = main
[core]
editor = code --waitExpected result
A line added or changed in the relevant file; the next Git command uses it. No output on success.
Common mistakes
- Typo in the key.
git config --global user.nmaeis stored silently (exit code 1, no message) and never used. Read back with--list. - Wrong level. Set inside a repository without
--globalapplies only there. - Expecting existing commits to change after fixing the email. Configuration is for future commits.
- Quoting. Values with spaces need quotes.
How to undo or recover
git config --global --unset <key>, or edit the file with --edit and delete the line.
In VS Code
No settings page for Git's own config; use the integrated terminal. VS Code's git.* settings (Settings, search "git") configure the extension, not Git.
In IntelliJ IDEA
Settings → Version Control → Git covers the executable path and a few behaviours; identity and the rest come from ~/.gitconfig (use the terminal).
Related commands
None directly; every other command reads what config wrote. git remote is a specialized editor for the [remote] sections of .git/config.
Lessons that use this command
First-time configuration · Configuration levels · A starter configuration.