git_config

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

Sample .gitconfig file:

TO DO:

  • GIT_CONFIG
  • GIT_CONFIG_NOSYSTEM
$ 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

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

$ git config --global user.name "Robert P. J. Day"
$ git config --global user.email "rpjday@crashcourse.ca"

$ 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 alias.br branch
$ git config --global alias.cm commit
$ git config --global alias.cl clone

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

[user]
	email = rpjday@crashcourse.ca
	name = Robert P. J. Day
[color]
	ui = false

and so on.

To delete a configuration setting, add --unset:

$ git config --global --unset alias.br

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

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

Typically not used; settable only by root.

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

Per-user:

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

Repository-specific (Linux kernel source repo):

$ cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = https://github.com/torvalds/linux.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[gui]
	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.

$ git config [--get] user.name
Robert P. J. Day
$
$ git config [-l|--list]
$ git config -l --local
$ git config -l --global
$ git config -l --show-origin
file:/home/rpjday/.gitconfig    user.email=rpjday@crashcourse.ca
file:/home/rpjday/.gitconfig    user.name=Robert 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=https://github.com/torvalds/linux.git
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 user.name
file:/home/rpjday/.gitconfig	Robert P. J. Day
$

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:

  • GIT_AUTHOR_NAME
  • GIT AUTHOR_EMAIL

For the full list:

$ man git

If you need a one-time-only override of some config setting, most Git commands support the ā€œ-cā€ option:

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

Format of <section>.<key>:

  • user.name
  • user.email
  • 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
  • UsEr.nAmE
  • REMOTE.origin.URL
  • BrAnCh.master.meRGE
  • git_config.txt
  • Last modified: 2019/02/18 09:57
  • by rpjday