Git Config (git-config) Command Tutorial

The git config command is used to configure Git installation for the system-wide or current users or for a specific repository. The git config command provides a lot of different options to configure like default editor, user email, user name, merge tool, output coloring, command alias, etc. In this tutorial, we examine the general usage of the git config command with examples.

git config Syntax

The git config command syntax is like below.

git config CONF_LEVEL CONFIG CONFIG_VALUE
  • CONF_LEVEL is the configuration level which is set the configuration for different levels like system-wide, the current user, or the current repository. The --global , --user and --local options are used to set the configuration level. The configuration level usage is described below in detail.
  • CONFIG is the configuration name that can be user.email etc. configured.
  • CONFIG_VALUE is the configuration values related to the CONFIG.

Git Configuration Levels

Git provides 3 different levels to set configuration.

--global level is used to set specified configuration for the whole system. But this configuration requires administrator privileges. As an example, a system-wide or global level configuration can be set like below.

$ git config --global user.name "İsmail Baydan"

--user level is used to set configuration for the current user. Even if there is a global level configuration the user-level configuration is preferred over it.

$ git config --user user.name "İsmail Baydan"

--local level is used to set configuration for a specific repository. Event there is a global or user-level configuration the local level configuration is preferred over them.

$ git config --local user.name "İsmail Baydan"

Configure git config Editor

Most of the git commands launch a text editor during execution. This editor can be a command-line interface editor or GUI-based editor. The editor can be configured by using the git config core.editor command providing the editor command. In some cases, the command may need an option that can be also specified with the git config core.editor command.

EditorGit Configuration 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”
Textmategit config –global core.editor “mate -w”

Configure User Email

The most popular usage of the git config is configuring the user email with the git config user.email command.

Global Level

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

User Level

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

Repository Level

$ git config --local user.email "[email protected]"

Configure User Name

Another popular usage for the git config is changing or setting the user name with the git config user.name command.

Global Level

$ git config --global user.name "İsmail Baydan"

User Level

$ git config --user user.name "İsmail Baydan"

Repository Level

$ git config --local user.name "İsmail Baydan"

Configure Merge Tool

During the usage of the git command, there are different cases where some merge conflict may occur. These merge conflicts are solved by using merge tools that generally provide diff functions. The git config merge.tool is used to specify the merge conflict tool.

Global Level

$ git config --global merge.tool kdiff3

User Level

$ git config --user merge.tool kdiff3

Repository Level

$ git config --local merge.tool kdiff3

Configure Command Alias

Git provides a lot of commands and subcommands which may increase the complexity of the commands. This may also prevent easy remembering and usage of the commands too. An alias can be used for short commands by creating an alias for easy access. The git config alias command. The alias command syntax is like below.

git config alias.ALIAS_COMMAND GIT_COMMAND
  • ALIAS_COMMAND is the new alias used to call GIT_COMMAND in a short way.
  • GIT_COMMAND is the long command which is called when the ALIAS_COMMAND is used.

In the following example, we create an alias for the git pull command as p . So just calling git p triggers the git pull command.

Global Level

$ git config --global alias.p "git pull"

User Level

$ git config --user alias.p "git pull"

Repository Level

$ git config --local alias.p "git pull"

Enable or Disable Colored Output

Git commands put a lot of output with different syntax. Coloring these outputs makes them easier to read. The colored output can be enabled with the git config color.ui command.

Global Level

$ git config --global color.ui true

User Level

$ git config --user color.ui true

Repository Level

$ git config --local color.ui true

Or we can disable the colored output with the following commands.

Global Level

$ git config --global color.ui false

User Level

$ git config --user color.ui false

Repository Level

$ git config --local color.ui false

Leave a Comment