git config

Setup & Creating Projects

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] --list
[ ] optional| or<arg> placeholder... repeatable--flag option

Options

Click any option to expand

Beginner (3)

Read or write your user settings (~/.gitconfig), shared by every repository.

RecommendedSet your identity and preferences once for all projects

Example

git config --global user.name "Ada Lovelace"

Remove a setting.

When neededRemove a setting to fall back to the default

Example

git config --unset pull.rebase

List every setting in effect, with its value.

When neededDebug which settings apply and where they come from

Example

git config --list --show-origin

Choosing the Right Option

Where settings live

The most specific one wins

CommandFileApplies to
--system/etc/gitconfigEvery user of the computer
--global~/.gitconfigAll your repositories
--local (default).git/configThis 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.com

Also used on every commit.


Read a setting

git config user.name

Prints the value in effect here.


Default branch name

git config --global init.defaultBranch main

git init will start on main.

Workflow Examples

1
git config --global user.name "Ada Lovelace"

Your name

2
git config --global user.email ada@example.com

Your email

3
git config --global init.defaultBranch main

New 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

A:

~/.gitconfig (on Windows: C:\Users\<you>\.gitconfig).

A:

git config --global core.editor "code --wait".