Reputation: 361
I have two related questions:
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?
Upvotes: 25
Views: 17187
Reputation: 2512
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:
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:
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.
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
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
Upvotes: 5
Reputation: 45649
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.
Upvotes: 29
Reputation: 239301
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.
Upvotes: 3