git configuration

created onJune 22, 2022
last modified onOctober 28, 2023

config files

git comes with three config files

applies path
system wide settings /etc/gitconfig values can be set by the system administrator with the –system option
all repos initialized or cloned by user ~/.gitconfig or ~/.config/git/config values can be set by the user with the –global option
config file for specific repo .git/config (config file in git dir of repo) values can be set by the user with the –local option

Each level overrides values in the previous level(s), so values in the repo specific config override those in , which in turn override the values in .

Config values are set with the command, i.e. to set the username config value in your with , run:

git config --global user.name 'alice'

Alternatively, the config file can be edited directly with an editor.

For an initial setup, set your username, email, your preferred editor and merge tool in the git config. The config values are listed in the tables below.

user config values

config value usage
user.email your email address, will be recorded in any commit created by you
user.name your (full) name, will be recorded in any commit created by you under author and commiter, as long as you do not set the author explicitly.
user.signingKey specifies the key that will be used when you create a signed tag or commit. This config value is passed unchanged to gpg’s –local-user parameter
user.useConfigOnly useful if you have several repos and want different user names and email addresses to be set for each repo. If user.useConfigOnly is set to true in your global config, git will prompt you to set up an email before making new commits in a newly cloned or initialized repository. Defaults to false.

merge tool values

config value usage
merge.tool specifies the merge tool that is fired up when running git merge. Valid values for merge tools are listed below. If your merge tool is not in this list, you have to use the config value mergetool.<tool>.cmd instead

merge tools supported with merge.tool

in alphabetical order:

  • araxis
  • bc, bc3
  • codecompare
  • deltawalker, diffmerge, diffuse
  • ecmerge, emerge, examdiff
  • gvimdiff, gvimdiff2, gvimdiff3
  • kdiff3
  • meld
  • opendiff
  • p4merge
  • tkdiff, tortoisemerge
  • vimdiff, vimdiff2, vimdiff3
  • winmerge
  • xxdiff

custom merge tool values

config value usage
mergetool.<tool>.cmd specifies the command to invoke the custom merge tool. The command is evaluated in shell with the following variables available: BASE is the name of a temporary file containing the common base of the files to be merged, if available; LOCAL is the name of a temporary file containing the contents of the file on the current branch; REMOTE is the name of a temporary file containing the contents of the file from the branch being merged; MERGED contains the name of the file to which the merge tool should write the results of a successful merge.
mergetool.<tool>.trustExitCode for a custom merge command, specify whether the exit code of the merge command can be used to determine whether the merge was successful. If this is set to false then the merge target file timestamp is checked and the merge assumed to have been successful if the file has been updated, otherwise the user is prompted to indicate the success of the merge.
mergetool.prompt prompt before each invocation of the merge tool

listing config values

Config values can be listed with . Your current working directory (in terms of shell, value of ${PWD}, not git) must be inside of a git repo to list the config values specfic for that repo. If your current working directory is outside of a git repo, only the system-wide config values and your user specific config values are listed

Example output:

http.sslcainfo=./root-ca.pem user.name=rudolf user.email=rudolf@codebase.zone core.editor=joe ... (some lines omitted)

To show the config files from which the config values have their effective value, run . Example output:

file:/etc/gitconfig http.sslcainfo=./root-ca.pem file:/home/rudolf/.gitconfig user.name=rudolf file:/home/rudolf/.gitconfig user.email=rudolf@knusperfisch.de file:/home/rudolf/.gitconfig core.editor=joe ... (some lines omitted) file:.git/config remote.origin.url=gitea@idoru:sites/codebase.git

reference

git config man page (run )