W3docs

git config

On this page, you can find information about git config. Read about the usage of git config, learn the levels and tools, as well as see how to create value.

What is git config

The git config command is a command-line utility for reading and writing Git's configuration variables — the settings that control how Git looks and behaves. These variables define your identity (name and email), your preferred text editor, output colors, command shortcuts (aliases), and dozens of other behaviors.

This page covers the configuration levels and their files, how to read and write values, setting your editor and colors, creating aliases, and tuning whitespace handling. Setting user.name and user.email with git config is usually the very first thing you do after installing Git.

gitconfig

The git config levels and files

The git config command accepts arguments to specify on which configuration level to operate. When looking for a configuration value, Git prioritizes the following order (from lowest to highest priority):

  1. --system – The system-level configuration includes all users on an operating system and all repositories. The system-level configuration file is located in the Git installation directory.

git config system level

(prefix)/etc/gitconfig - on Unix systems
C:\Documents and Settings\All Users\Application Data\Git\config - Windows XP (deprecated)
C:\ProgramData\Git\config - Windows Vista and newer versions
  1. --global – The global-level configuration applies to the current operating system user. Global configuration values are stored in a file in the user's home directory.

git config global level

~/.gitconfig - on Unix systems
C:\Users\<username>\.gitconfig - on Windows
  1. --local – When no configuration option is passed, git config writes to the local level by default. The repository's .git directory contains a file that stores local configuration values.

git config local level

.git/config

Note: Local settings override global settings, which in turn override system settings. So a user.email set inside one repository (local) wins over the global value, letting you use a work address in one project and a personal address in another.

How to write a value

To write a value, pass the configuration name followed by the value. The example below writes [email protected] to user.email. The --global flag sets the value for the current operating system user, so it applies to every repository you work in:

git config set user

git config --global user.email "[email protected]"

A typical first-time setup writes both your name and email:

git config --global user.name "Jane Doe"
git config --global user.email "[email protected]"

These two values are stamped onto every commit you create, so set them before your first commit.

How to read a value

The basic use of git config is to retrieve a configuration value by specifying its name. Configuration names consist of a section and a key separated by a dot:

git config user email

git config user.email

Here, email is a child property of the user section. Running this prints the active value — the one that wins after the local → global → system override chain is applied.

Useful inspection commands

Beyond reading a single key, these commands help you see and manage everything Git has configured:

CommandWhat it does
git config --listLists every active setting, merged across all levels.
git config --list --show-originLists each setting alongside the file it comes from.
git config --get-all <key>Retrieves all values for a key that can be set more than once.
git config --unset <key>Removes a single setting.
git config --editOpens the relevant config file in your default editor.

When two levels define the same key, --show-origin is the quickest way to find out which file is responsible for the value Git actually uses.

The git config editor - core.editor

When your identity is set up, Git uses your system’s default editor, which is Vi or Vim. The git config sets up which editor Git will use. Here is the list of most common editors with git config commands:

EditorConfig Command
Atomgit config --global core.editor "atom --wait"
emacsgit config --global core.editor "emacs"
nanogit config --global core.editor "nano -w"
vimgit config --global core.editor "vim"
Sublime Text (Mac)git config --global core.editor "subl -w"
Sublime Text (Win, 32-bit install)git config --global core.editor "'c:/program files (x86)/sublime text 3/sublimetext.exe' -w"
Sublime Text (Win, 64-bit install)git config --global core.editor "'c:/program files/sublime text 3/sublimetext.exe' -w"
Textmategit config --global core.editor "mate -w"

Colored outputs

Git supports colors thus simplifying the process of reading Git output. You can use your colors for customizing the output. For setting color values git config command is used.

color.ui

Git automatically colors most of its output, but there is also a master variable if you want to set another color. For disabling all Git's colored terminal output you can do the following:

git config set color.ui

git config --global color.ui false

The default setting of color.ui is auto which applies colors directly to the terminal output. It omits color code output when the output is redirected to a pipe or a file.

You can also set the color.ui value to always. It applies color code output when the output is redirected to files or pipes. This can cause problems as the receiving pipe may not be expecting color-coded input.

Git color values

Besides color.ui, there are also other color settings that can be set to false, auto, or always. They can have a specific color value: normal, black, red, green, yellow, blue, magenta, cyan, white. Colors can be specified as hexadecimal color codes like #1c87c9 or ANSI 256 color values if the terminal supports it.

Git color configuration settings

SettingDescription
color.branchSets up the output color of the Git branch command.
color.branch.<slot>Is relevant to Git branch output. <slot> is one of the following: 1. current branch 2. local branch 3. remote branch 4. upstream branch 5. plain (any other ref)
color.diffGives colors to git diff, git log, and git show output
color.diff.<slot>Instructs git on which part of the patch (context, plain, meta, frag, old, new, commit, whitespace) a specific color should be used.
color.decorate.<slot>Adjusts the color for git log --decorate output. The supported <slot> values are branch, remote Branch, tag, stash, or HEAD. They are applied to local branches, remote-tracking branches, tags, stashed changes and HEAD, respectively.
color.grepGives color to the output of git grep.
color.grep.<slot>It can be applied to git grep. The <slot> variable specifies to which part of the grep output (context, filename, function, line number, match, match Context, match Selected, selected, separator) color should be applied.
color.interactiveGives color for interactive prompts and displays (e.g. git add --interactive, git clean --interactive)
color.interactive.<slot>Targets an "interactive output". The available <slot> values are: prompt, header, help, error.
color.pagerEnables or disables colored output when the pager is in use.
color.showBranchEnables or disables color output for the git show branch command.
color.statusEnables or disables color output for Git status.
color.status.<slot>Specifies custom color for defined git status elements. <slot> supports the following values: header, added or updated, changed, untracked, branch, nobranch, unmerged.

The git config aliases

Aliases are custom shortcuts that expand to longer or combined commands, so you don't have to retype frequently used commands in full. Git's alias system is most often used to shorten common commands. You create aliases with git config:

git config set alias

git config --global alias.ci commit

After this, git ci runs git commit. Because the value contains a space, an alias that maps to a command with flags must be quoted as a single argument:

git config aliases

git config --global alias.amend "commit --amend"

Here, running git amend expands to git commit --amend. An alias can also call out to a shell command by prefixing the value with !, for example git config --global alias.unstage '!git restore --staged'. For a deeper dive, see the dedicated git alias chapter.

Formatting & whitespace

FeatureDescriptionGit Config Command
indent-with-non-tabHighlights a line starting with spaces instead of tabs.git config --global core.whitespace "indent-with-non-tab,tab-in-indent,blank-at-eof,-trailing-space,-cr-at-eol"
tab-in-indentHighlights an initial tab indent as an error.(Combined with other rules)
blank-at-eofHighlights blank lines inserted at the end of a file.(Combined with other rules)
trailing-spaceHighlights trailing whitespace.(Combined with other rules)
cr-at-eolHighlights a carriage-return at the end of the line.(Combined with other rules)
tabwidth=<n>Specifies how many character positions a tab occupies. Default is 8. Allowed values: 1-63.git config --global core.whitespace "tabwidth=<n>"

Other common settings

A few configuration values are worth setting on a new machine:

# Name the default branch "main" for every repository you create
git config --global init.defaultBranch main

# Reuse cached credentials so you are not prompted on every push
git config --global credential.helper cache

# Choose how git pull reconciles divergent branches (merge, not rebase)
git config --global pull.rebase false

The init.defaultBranch value is applied by git init when a repository is created. To control which files Git tracks at all, pair your config with a .gitignore file.

Practice

Practice
Which of the following is a correct use of the 'git config' command?
Which of the following is a correct use of the 'git config' command?
Was this page helpful?