User Tools

Site Tools



How to examine, set and unset your Git configuration with git config (uses INI file format).

Sample .gitconfig file:




$ man git-config

 ... snip ...

git config [<file-option>] [type] [--show-origin] [-z|--null] name [value [value_regex]]
git config [<file-option>] [type] --add name value
git config [<file-option>] [type] --replace-all name value [value_regex]
git config [<file-option>] [type] [--show-origin] [-z|--null] --get name [value_regex]
git config [<file-option>] [type] [--show-origin] [-z|--null] --get-all name [value_regex]
git config [<file-option>] [type] [--show-origin] [-z|--null] [--name-only] --get-regexp name_regex [value_regex]
git config [<file-option>] [type] [-z|--null] --get-urlmatch name URL
git config [<file-option>] --unset name [value_regex]
git config [<file-option>] --unset-all name [value_regex]
git config [<file-option>] --rename-section old_name new_name
git config [<file-option>] --remove-section name
git config [<file-option>] [--show-origin] [-z|--null] [--name-only] -l | --list
git config [<file-option>] --get-color name [default]
git config [<file-option>] --get-colorbool name [stdout-is-tty]
git config [<file-option>] -e | --edit

Basic configuration examples

Configuration settings of the form <section>.<key>:

$ git config --global "Robert P. J. Day"
$ git config --global ""

$ git config --global core.editor vim
$ git config --global core.whitespace "fix,-indent-with-non-tab,trailing-space,cr-at-eol"

$ git config --global branch.current "yellow bold"
$ git config --global branch.local "green bold"
$ git config --global branch.remote "cyan bold"

$ git config --global color.ui false

$ git config --global branch
$ git config --global commit
$ git config --global clone

All of the above (based on specifying --global) end up in your (INI-style) personal ~/.gitconfig file with the form:

	email =
	name = Robert P. J. Day
	ui = false

and so on.

To delete a configuration setting, add --unset:

$ git config --global --unset

Three levels of configuration

In order of processing (later settings override earlier ones):

  • system (/etc/gitconfig)
  • global (~/.gitconfig)
  • local (.git/config) [associated with the repo itself]

/etc/gitconfig (--system)

Typically not used; settable only by root.

$ cat /etc/gitconfig
cat: /etc/gitconfig: No such file or directory

~/.gitconfig (--global)


$ cat ~/.gitconfig
	email =
	name = Robert P. J. Day
	ui = false
	hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
        editor = vi
	excludesFile = /home/rpjday/.my_gitignore
	requireForce = false

.git/config (--local)

Repository-specific (Linux kernel source repo):

$ cat .git/config
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url =
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
	wmstate = normal
	geometry = 1116x800+689+93 219 227

NOTE: If you don't specify which of the three levels you want, the operation defaults to --local, which will fail if you are not inside a working tree, and is probably not what you want, anyway.

Listing config settings

Listing a single setting

$ git config [--get]
Robert P. J. Day

Listing them all, or some subset

$ git config [-l|--list]
$ git config -l --local
$ git config -l --global

See where config settings come from (--show-origin)

$ git config -l --show-origin
file:/home/rpjday/.gitconfig P. J. Day
file:/home/rpjday/.gitconfig    color.ui=false
file:/home/rpjday/.gitconfig    alias.hist=log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
file:/home/rpjday/.gitconfig    core.excludesfile=/home/rpjday/.my_gitignore
file:/home/rpjday/.gitconfig    clean.requireforce=false
file:.git/config        core.repositoryformatversion=0
file:.git/config        core.filemode=true
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        remote.origin.url=
file:.git/config        remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config        branch.master.remote=origin
file:.git/config        branch.master.merge=refs/heads/master
file:.git/config        gui.wmstate=normal
file:.git/config        gui.geometry=1116x800+689+93 219 227
$ git config --show-origin
file:/home/rpjday/.gitconfig	Robert P. J. Day

Overriding configuration settings

Environment variables

Most Git commands support environment variables for overriding configuration settings. As an example, git commit searches for the editor to use when entering the commit message:

  • GIT_EDITOR environment variable
  • core.editor configuration variable
  • VISUAL environment variable
  • EDITOR environment variable
  • vi editor

To change your identity, (some of) the environment variables:


For the full list:

$ man git

One-time config override with -c

If you need a one-time-only override of some config setting, most Git commands support the “-c” option:

$ git -c"Keyser Soze" <some command>...

Sections and subsections

Format of <section>.<key>:

  • core.editor
  • color.ui
  • format.pretty

Format of <section>.<subsection>.<key>:

  • remote.origin.url
  • branch.master.merge

Sections and keys are not case-sensitive, while (weirdly) those middle subsections are:

  • UsEr.nAmE
  • REMOTE.origin.URL
  • BrAnCh.master.meRGE
git_config.txt · Last modified: 2019/02/18 09:57 by rpjday