w3docs logo


The git config command is a function that sets configuration variables. It controls git look and operation.


The git config levels and files

The git config accepts arguments to specify on which configuration level to operate. When looking for a configuration value, Git prioritizes the following order of configuration levels:

  1. --local

    When no configuration option is passed git config writes to a local level, by default.The repository of the .git directory has a file that stores local configuration values.

  2. --global

    The application of the global level configuration includes the operating system user. Global configuration values can be found in a file placed in a user's home directory.

    ~ /.gitconfig - on unix systems 
     C:\Users\<username>\.gitconfig - on windows
  3. --system

    The System-level configuration includes all users on an operating system and all repositories. System-level configuration file is located in a git config file of the system root path.

    (prefix)/etc/gitconfig - on unix systems
    C:\Documents and Settings\All Users\Application Data\Git\config - Windows XP
    C:\ProgramData\Git\config - on Windows Vista and newer versions.

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 --global user.email "[email protected]"

The git config usage

The basic use of git config is creating it with a configuration name that displays the set value at that name. Configuration names consist of a ''section'' and a ''key'' separated by a dot.

git config user.email

Here, email is a child property of the user configuration block.

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:

Editor Config Command
Atom git config --global core.editor "atom --wait"
emacs git config --global core.editor "emacs"
nano git config --global core.editor "nano -w"
vim git config --global core.editor "vim"
Sublime Text (Mac) git config --global core.editor "subl -n -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"
Textmate git config --global core.editor "mate -w"

Merge tools of git config

Git uses one of the merge tools in the case of a merge conflict. Git uses an internal implementation of the Unix diff program, by default. Besides, there are a lot of external third party merge conflict resolutions used instead.

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.


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 --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.branch Sets 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.diff Gives 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.grep Gives 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.interactive Gives 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.pager Enables or disables colored output when the pager is in use.
color.showBranch Enables or disables color output for the git show branch command.
color.status Enables 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 --global alias.ci commit

Aliases can create super-powerful combinations with other 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

Enabled Features by Default
indent-with-non-tab Highlights a line starting with spaces instead of tabs.
tab-in-indent Highlights an initial tab indent as an error.
blank-at-eof Highlights blank lines inserted at the end of a file.
Disabled Features by Default
indent-with-non-tab Highlights a line starting with spaces instead of tabs.
tab-in-indent Highlights an initial tab indent as an error.
trailing-space Is shorthand for blank-at-eol and blank-at-eof
cr-at-eol Highlights a carriage-return at the end of the line.
tabwidth=<n> Specifies how many character positions a tab occupies. The default value is 8. Allowed values are 1-63.

Do you find this helpful?