===== Overview ===== How to examine, set and unset your Git configuration with ''git config'' (uses INI file format). Sample ''.gitconfig'' file: * [[https://gist.github.com/pksunkara/988716]] TO DO: * ''GIT_CONFIG'' * ''GIT_CONFIG_NOSYSTEM'' ===== SYNOPSIS ===== $ man git-config ... snip ... git config [] [type] [--show-origin] [-z|--null] name [value [value_regex]] git config [] [type] --add name value git config [] [type] --replace-all name value [value_regex] git config [] [type] [--show-origin] [-z|--null] --get name [value_regex] git config [] [type] [--show-origin] [-z|--null] --get-all name [value_regex] git config [] [type] [--show-origin] [-z|--null] [--name-only] --get-regexp name_regex [value_regex] git config [] [type] [-z|--null] --get-urlmatch name URL git config [] --unset name [value_regex] git config [] --unset-all name [value_regex] git config [] --rename-section old_name new_name git config [] --remove-section name git config [] [--show-origin] [-z|--null] [--name-only] -l | --list git config [] --get-color name [default] git config [] --get-colorbool name [stdout-is-tty] git config [] -e | --edit ===== Basic configuration examples ===== Configuration settings of the form ''
''.'''': $ 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: $ 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 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] 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 ===== ==== 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: * ''GIT_AUTHOR_NAME'' * ''GIT AUTHOR_EMAIL'' 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 user.name="Keyser Soze" ... ===== Sections and subsections ===== Format of ''
.'': * ''user.name'' * ''user.email'' * ''core.editor'' * ''color.ui'' * ''format.pretty'' Format of ''
..'': * ''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''