52

I am a beginner to Git. I go through the internet and find those.

What I know are

  • Local -: Values in this file apply to a single repository.
  • Global -: Configuration values in this file are applied to a single user.

Can I know any other differences between these configurations?

1

4 Answers 4

60

Git comes with a tool called git config that lets you configure variables that control all the aspects of how git will operate.

git config holds its value between upgrades. So, you need to set it only once.

Basically, there are 3 places to store these variables:

  1. System.
  2. Global.
  3. Local.

1. System: These variables are available for every user in the system and stored in

[path]/etc/gitconfig.
Example: C:/Program Files/Git/etc/gitconfig

You can make git read and write from System by passing --system as option. It also requires you to have administration permissions.


2. Global: Global configurations are available for the current user for all the projects and stored in

~/.gitconfig or ~/.config/git/config
Example: C:/Users/Username/.gitconfig

You can make git to read and write from Global by passing --global option.


3. Local: Local configs are available for the current repository only and stored in

[gitrepo]/.git/config
Example: C:/Users/MyProject/.git/config

You can make git read and write from Local by passing --local option.


Example:

Create a local config $ git config --local user.name "Local User" # Create a global config $ git config --global user.name "Global User" # Create a system config $ sudo git config --system user.name "System User" 

to verify the origin of your configuration :

git config --list --show-origin 

Also, its important to remember each level overrides values the previous level.

Priority:

Local > Global > System

Sign up to request clarification or add additional context in comments.

4 Comments

There is since last year --show-scope which names the level.
The best comes last..Btw "If you don’t specify which level you want to work with, this, local is the default" as another answer here states.
About --show-scope use it as git config --list --show-scope
BTW for macOS the location for system is at /usr/local/git/etc/gitconfig
39

Git uses a hierarchical config approach in which settings of a broader scope are inherited if not overriden.

On the top level is the system config (all users, usually in /etc/git), then there is the global config (which can override system defaults with personal ones, located in the home directory of the user, e.g. $HOME/.gitconfig or $HOME/.config/git/config) and finally there is the local config for a repository (.git/config in the repository root) which can override all above and set repository specific options.

All configuration files have the same syntax, but a different scope.

This offers a lot of flexibility.

5 Comments

Which one is more used .gitconfig or .config/git/config? I think the first.
The first is more common I think
If you use Git for WIndows and %HOME% is not set, Git uses %HOMEDRIVE%%HOMEPATH%.
BTW for macOS the location for system is at /usr/local/git/etc/gitconfig
And if you're using git installed via homebrew, the system will be located in /opt/homebrew/etc/gitconfig
7

Local level configuration is applied to the context repository git config gets invoked in. Local configuration values are stored in a file that can be found in the repo's .git directory: .git/config. If you don’t specify which level you want to work with, this is the default.

Whereas, global configuration values are stored in a file that is located in a user's home directory. ~ /.gitconfig on Unix systems and C:\Users\<username>\.gitconfig on windows

Comments

0

Just a little note, as opposed to other comments mentioned here, typing "git config --list" will output hybrid config values and not only local config. In other words, the default of "git config --list" in a project is not --local

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.