22

I have two related questions:

  1. How can I determine precisely which config file is being used by my Git bash client?
  2. Can I override settings in the config file being used?

I know that there is a system, global and local (aka project) .gitconfig file. And, according to the Git site, each of these "levels" (system, global, local) overwrites values in the previous level, so values in the ./git/config (local) trump those in /etc/gitconfig, for instance.

In other words we are dealing with a hierarchy and any declaration in the local config file will take precedence over one in the global or system config file.

But, if a setting is present in say the global file (say proxy) and not present in the local file does that setting then use the proxy setting from global? That would mean that Git works with all the settings in all the config files before applying the hierarchy rule.

And then, in the example above, if the proxy setting from global is being used together with the other settings in my local config file how can I override it?

Flip
  • 6,233
  • 7
  • 46
  • 75
P. Cartier
  • 331
  • 1
  • 2
  • 6
  • 1
    [With Git 2.26 (Q1 2020)](https://stackoverflow.com/a/60286340/6309), the full command would be `git config --list --show-origin --show-scope` – VonC Feb 18 '20 at 17:28

3 Answers3

24

How can I determine precisely which gitconfig file is being used by my Git bash client ?

You can use the --show-origin option

git config --list --show-origin

This will show the file from which each setting's value was taken.

Can I override settings in the Git config file being used ?

You can override settings from lower-precedence sources by putting the value you want to use instead in a higher-precedence source.

I've read your example, and I'm really not sure I get the question. If the proxy setting is in your global file, then as you already pointed out yourself you can override it by putting a value in the local file.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • The point is I would like to know which config I am ACTUALLY USING. the command you pro – P. Cartier Mar 14 '17 at 14:11
  • ...vided tells you which config you are ACTUALLY USING. (Thought I'd finish the thought since you trailed off.) – Mark Adelsberger Mar 14 '17 at 14:19
  • On the override issue ... I want to override what is in the global so will have to put specific settings in the local file as Meagar states above. Pretty inelegant as there are quite a few of them! But is is as it is. – P. Cartier Mar 14 '17 at 14:30
  • On which config is used ... the point is I would like to know which config I am ACTUALLY USING. The command you provide does not work with me ... probably because I do not have a connection to the repo right now. I have a repo I once cloned and credentials have changed and now I need to connect again and cannot. I have several other GIT repos on my system which all use mainly settings in the global or system cf quite happily. – P. Cartier Mar 14 '17 at 14:30
  • What do you mean "...do not have a connection to the repo..."? Do you mean you're not able to reach the remote? Doesn't matter; git doesn't use the remote for configuration. The whole point of git is that it's distributed, so you don't need a connection to anything (except to fetch, pull, or push) – Mark Adelsberger Mar 14 '17 at 14:33
  • As for overriding by placing the desired values in local being "inelegant"... if you want to change a lot of values, how do you expect to do that without listing out a lot of values? Of *course* you have to put them in the local file, because that's the higher-precedence source. – Mark Adelsberger Mar 14 '17 at 14:35
  • I am aware of the distributed nature of GIT. the cmd "git config --list --show-origin" quite simply did not work ... and it occurred to me that it might be trying to show more than just the origin specified in a config file and therefore require a connection – P. Cartier Mar 15 '17 at 10:25
  • Anyway, the "git config --list --show-origin" cmd still does not work on my system - connection or no-connection. I checked and if referential integrity has been broken then you should use "git config --get remote.origin.url". This works without a connection. – P. Cartier Mar 15 '17 at 10:34
  • I find the GIT impl "inelegant" because it involves replacing a whole lot of values with default values locally to effectively create a simple, stripped down configuration. In this situation you would expect that you would be able to point to a specific single, simple config file via a switch or suchlike (I understand there is a GIT_CONFIG env variable but I couldn't get this to work). Just another reason why GIT would not be my SCM of choice. Anyway, appreciations all for your input. I have a working "solution" and nearly done on this project! – P. Cartier Mar 15 '17 at 11:02
  • 1
    You expect that if you give a tool a bunch of global configs that override defaults, there should be a simple way other than changing where it looks for global configs to restore defaults for all those values it was given without having to list out the overrides? The tool isn't the problem. – Mark Adelsberger Mar 15 '17 at 12:30
4

1. You can view all of your settings and where they are coming from using:

$ git config --list --show-origin

The origin of the settings could be from 1 out of 3 different configuration files which are listed below.

2. Git Environment setup:

Git_config_visualisation

When you install git on your system, you’ll want to do a few things to customize your Git environment. Git has a tool called git config that lets you get and set configuration variables that control all aspects of how Git operates. They can be stored either in one of the 3 places as illustrated above.

Considering you have a windows environment:

  • System level [git config --system]:

You can edit/view the configuration set by git at system level using this command. By default it applies to every user on the system and all their repositories. If you are using version 2.x or later of Git for Windows, there is also a system-level config file at 'C:\Documents and Settings\All Users\Application Data\Git\config' on Windows XP and in 'C:\Program Data\Git\config' on Windows Vista and newer.

  • User level [git config --global]:

I know that the --global flag could be misleading but remember this that the configuration settings applies specifically to you i.e. the current user with which you're currently logged in. You can make Git read and write to this file specifically by passing the --global option, and this affects all of the repositories you work with on your system. On windows git looks for this file in the home directory i.e C:\Users\$USER\.gitconfig

  • Directory level [git config --local]:

You can force Git to read from and write to this file with the --local option. You can find this config file in the .git directory of whatever repository you’re currently using. Anyone can view/edit these configuration settings.

Note: Each level overrides values in the previous level, so values in .git/config overrides values in Users\$USER\.gitconfig

Tahir77667
  • 2,290
  • 20
  • 16
3

That would mean that Git works with all the settings in all the config files before applying the hierarchy rule.

Yes. The results are additive. Settings in each level are merged with the settings in the previous level. When both levels specify the same setting, the lower more specific setting overwrites the less specific one.

as git configuration documentation clearly states:

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.

As for your second question,

And then, in the example above, if the proxy setting from global is being used together with the other settings in my local config file how can I override it?

Provide a more specific setting in the local config for the project.

Stavm
  • 7,833
  • 5
  • 44
  • 68
user229044
  • 232,980
  • 40
  • 330
  • 338
  • OK. Thanks for your answer ... I thought there might be a way to use just one specific file for a repo. You would expect this. Anyway ... the "additive" results means indeed that I need to provide more specific settings in the local config for the project. It means that if I have 10 declarations in the global but on a particular repo just need 2 simple ones I still need to override the other 8 in the local file with blank strings or default values – P. Cartier Mar 14 '17 at 14:02