Saturday, October 21, 2017

GIT Config Settings and their Precedence

logo2x

It is helpful to setup GIT default user name and email so you don't have to type it every time when you push commits to remote.  At the same time, you may have different remote accounts such as github, bitbucket etc. with different user names and emails.  So how do you manage that?  Fortunately, GIT designers have already thought about this.  GIT config command comes with three different options:
$ git config --system user.name "terry yakky" $ git config --system user.email terry@example.com
$ git config --global user.name "barry yakky" $ git config --global user.email barry@example.com
$ git config --local user.name "larry yakky" $ git config --local user.email larry@example.com

--system option

The specified user name and email value apply for every user of the computer on the system and all of the repositories.  The config file is stored at /etc/gitconfig

--global option

The specified user name and email values apply to the current logged in user and all of the repositories under this login.  The config file is stored at ~/.gitconfig (or ~/.config/git/config)

--local option

The specified user name and email values apply to the current repository directory.  The config file is stored at .git/config in the GIT directory.

And the precedence is local trumps global, global trumps system.  If a setting is not found in local, GIT looks for it in global, if not in global, in system.

And this precedence and fallback rule apply to other config settings as well.

About Cullen

My photo
Christian, Father, Software Developer/Architect who enjoys technology and using it to make people's lives easier!

Followers