Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between global and local configuration in git?

Tags:

git

git-config

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?

like image 400
Kalana Avatar asked Feb 13 '20 07:02

Kalana


People also ask

What is global configuration in git?

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.

What are the different configuration levels in git?

# There are 3 levels of git config; project, global and system.

What is git local config?

Local config is a popular feature among data scientists and analysts working on laptops. It allows users to store personal Exasol credentials and connection options in local file and separate it from code. In order to use local config, please create file ~/.pyexasol.ini in your home directory.

What is local config?

The Local Configuration Manager (LCM) is the engine of Desired State Configuration (DSC). The LCM runs on every target node, and is responsible for parsing and enacting configurations that are sent to the node.


3 Answers

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.

like image 153
MrTux Avatar answered Nov 02 '22 22:11

MrTux


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 users 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

like image 28
Zahid Khan Avatar answered Nov 02 '22 23:11

Zahid Khan


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

like image 41
shrikant1712 Avatar answered Nov 02 '22 22:11

shrikant1712