Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ===== 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 ===== <code> $ 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 </code> ===== Basic configuration examples ===== Configuration settings of the form ''<section>''.''<key>'': <code> $ 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 </code> All of the above (based on specifying ''%%--%%global'') end up in your (INI-style) personal ''~/.gitconfig'' file with the form: <code> [user] email = rpjday@crashcourse.ca name = Robert P. J. Day [color] ui = false </code> and so on. To delete a configuration setting, add ''%%--%%unset'': <code> $ git config --global --unset alias.br </code> ===== 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. <code> $ cat /etc/gitconfig cat: /etc/gitconfig: No such file or directory $ </code> ==== ~/.gitconfig (--global) ==== Per-user: <code> $ 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 </code> ==== .git/config (--local) ==== Repository-specific (Linux kernel source repo): <code> $ 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 </code> 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 ==== <code> $ git config [--get] user.name Robert P. J. Day $ </code> ==== Listing them all, or some subset ==== <code> $ git config [-l|--list] $ git config -l --local $ git config -l --global </code> ==== See where config settings come from (--show-origin) ==== <code> $ 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 $ </code> <code> $ git config --show-origin user.name file:/home/rpjday/.gitconfig Robert P. J. Day $ </code> ===== 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: <code> $ man git </code> ==== 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: <code> $ git -c user.name="Keyser Soze" <some command>... </code> ===== Sections and subsections ===== 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:57by rpjday