How is git configuration evaluated on commit?

I configure My First Git Repo and run;

git config --list 

I noticed that I have several entries for specific configuration values;

 core.autocrlf=input [...] core.autocrlf=false 

I assume that these values โ€‹โ€‹are doubled because they are displayed in several configuration files (system, global, file). My question is which of these values โ€‹โ€‹takes precedence? Is the configuration file read line by line and the last record taken as the one used during commit?

+3
git configuration
source share
2 answers

Borrowed from MYYN, these are three places where you can find configuration files:

  • $ GIT_DIR / configuration
  • ~ / .gitconfig (- global)
  • $ (prefix) / etc. / gitconfig

Well, imagine that you globally set your email address to niko.schwarz@gmail.com. Now we are creating a new repo:

 $ cd /tmp $ mkdir try && cd try $ git init $ git config user.email niko.schwarz@s-i.ch $ touch hi $ git -add . $ git commit -m 'bla' 

Then your user.email will be set to two values:

 $ git config --list | grep niko.schwarz user.email=niko.schwarz@gmail.com user.email=niko.schwarz@s-i.ch 

But if you look at the journal, the email address will be set to the one that relates to the repo:

 $ git log | grep niko.schwarz Author: Niko Schwarz < niko.schwarz@s-i.ch > Signed-off-by: Niko Schwarz < niko.schwarz@s-i.ch > 

Therefore, local bits are global; this is the order in which the values โ€‹โ€‹are listed. Now, turning over a bit, I would suggest that git config -list shows things in the order in which the latter take precedence.

+5
source share

Unless explicitly specified with --file , there are three files where git-config will look for configuration options:

  • $GIT_DIR/config

  • ~/.gitconfig ( --global )

  • $(prefix)/etc/gitconfig

If no additional parameters are specified, all read parameters will read all these available files. If a global or system-wide configuration file is not available, they will be ignored.

The .git/config file in each repository is used to store the configuration for this repository, and $HOME/.gitconfig used to store the configuration for each user as backup values โ€‹โ€‹for the .git/config file. The /etc/gitconfig can be used to store the system-wide default configuration.

Excellence should be from the most general to the repository related entries.

Or more memorable (borrowed from Niko): local beats global

+4
source share

All Articles