This is an old revision of the document!
Overview
How to examine, set and unset your Git configuration with git config (uses INI file format).
Sample .gitconfig file:
TO DO:
GIT_CONFIGGIT_CONFIG_NOSYSTEM
SYNOPSIS
$ 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 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
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)
Per-user (it would have killed them to call it --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
.git/config (--local)
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
Setting your configuration
Global configuration
Setting globally (in personal ~/.gitconfig):
$ git config --global user.name "Robert P. J. Day" $ git config --global user.email "rpjday@crashcourse.ca" $ git config --global color.ui false
Local configuration
Setting locally (in repo's .git/config):
$ git config [--local] gui.wmstate normal (the default mode)
Listing config settings
Listing a single setting
$ git config [--get] user.name 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 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 $
Overriding configuration settings
One-time config override with -c
$ git -c user.name="Keyser Soze" <command>...
Environment variables
As an example, git commit searches for the editor to use when entering the commit message:
GIT_EDITORenvironment variablecore.editorconfiguration variableVISUALenvironment variableEDITORenvironment variablevieditor
To change your identity, (some of) the environment variables:
GIT_AUTHOR_NAMEGIT AUTHOR_EMAIL
For the full list:
$ man git
Configuration sections and keys
Format of <section>.<key>:
user.nameuser.emailcore.editorcolor.uiformat.pretty
Format of <section>.<subsection>.<key>:
remote.origin.urlbranch.master.merge
Sections and keys are not case-sensitive, while (weirdly) those middle subsections are:
user.nameUsEr.nAmEREMOTE.origin.URLBrAnCh.master.meRGE