Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out which Git config file is used and how to override settings?

Tags:

git

git-config

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?

like image 564
P. Cartier Avatar asked Mar 14 '17 12:03

P. Cartier


People also ask

Which config file is git using?

The system level configuration file lives in a gitconfig file off the system root path. $(prefix)/etc/gitconfig on unix systems. On windows this file can be found at C:\Documents and Settings\All Users\Application Data\Git\config on Windows XP, and in C:\ProgramData\Git\config on Windows Vista and newer.

How do I change my git config file?

The global git config is simply a text file, so it can be edited with whatever text editor you choose. Open, edit global git config, save and close, and the changes will take effect the next time you issue a git command. It's that easy.


1 Answers

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.

like image 98
Mark Adelsberger Avatar answered Oct 11 '22 21:10

Mark Adelsberger