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.

Description

The git config command is a command-line utility that sets configuration variables. It controls Git's look and operation.

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.

How to write a value

Here, the example writes the value "[email protected]" to the configuration name user.email. The global level is used so as to set the value for the current operating system user.

git config set user

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

The git config usage

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 configuration block.

You can also list all active settings with git config --list, remove a setting with git config --unset <key>, or open the configuration file in your default editor with git config --edit. For modern workflows, git config --show-origin displays where each setting is defined, and git config --get-all <key> retrieves all values for a given key.

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

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 specifying which command will expand to longer or combined commands. There is no need for typing commonly used commands with aliases. Git has its own alias system which is mostly used to shorten git commit command. The git config command is used to configure aliases.

git config set alias

git config --global alias.ci commit

Aliases can create super-powerful combinations with other aliases.

git config aliases

git config --global alias.amend ci --amend

In the above-mentioned example, an alias amend composes the ci alias into a new alias that uses --amend

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>"

Practice

Practice

Which of the following is a correct use of the 'git config' command?