views:

124

answers:

2

I'm setting up My First Git Repo, and on running;

git config --list

I've noticed I've got multiple entries for certain config values;

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

I'm guessing these values are doubled up because they appear in more than one of the various config files (system, global, file). My question is, which of these values takes precedence? Is the config file read line by line, and the last entry taken as the one used during a commit?

+3  A: 

Borrowed from The MYYN, these are the three places where to find config files:

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

Ok, imagine you globally set your email to [email protected]. Now, we make a new repo:

$ cd /tmp
$ mkdir try && cd try
$ git init
$ git config user.email [email protected]
$ touch hi
$ git -add .
$ git commit -m 'bla'

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

$ git config --list | grep niko.schwarz
[email protected]
[email protected]

But if you look at the log, the email address will be set to the one specific to the repo:

$ git log | grep niko.schwarz
Author: Niko Schwarz <[email protected]>
    Signed-off-by: Niko Schwarz <[email protected]>

Therefore, local beats global, which is the order in which the values are listed. Now, with a bit of a leap of faith, I'd indeed assume that git config --list shows things in an order that makes latter ones take precedence.

nes1983
Thanks for the answer, but not for making me realise I could've performed this simple test myself; oh the shame! ;)
MatW
Very welcome :)
nes1983
+3  A: 

If not set explicitly with --file, there are three files where git-config will search for configuration options:

  • $GIT_DIR/config

  • ~/.gitconfig (--global)

  • $(prefix)/etc/gitconfig

If no further options are given, all reading options will read all of these files that are available. If the global or the system-wide configuration file are not available they will be ignored.

The .git/config file in each repository is used to store the configuration for that repository, and $HOME/.gitconfig is used to store a per-user configuration as fallback values for the .git/config file. The file /etc/gitconfig can be used to store a system-wide default configuration.

Precendence should be from the most general to the repository-specific entries.

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

The MYYN
Hihi, I like being quoted :) +1 for quoting
nes1983
its just that right and short and memorable ..
The MYYN