This article covers how to use the command 'git config'.
The git config command allows us to modify git configuration values, either:
- Locally - Within the current repository
- Globally - For every repository for the current operating system user
- System-wide - For every repository, and for every user on the system
These configuration values are saved within .gitconfig text files.
Values are stored in the config against a configuration name. To get the value for each configuration name, you can pass it to the git config command:
Get a configuration value
git config <configuration-name>
Let's look at an example:
$ git config user.name
Sean Lloyd
$ git config user.email
sean@email.com
Set a configuration value
To set a config value, we need to pass in the new value with the configuration name:
git config <configuration-name> <configuration-value>
For example, to change my name to "Sean P Lloyd":
$ git config user.name "Sean P Lloyd"
$ git config user.name
Sean P Lloyd
Setting different configuration levels
In the previous example, we set a configuration value without specifying the configuration level.
As mentioned previously, we have three configuration levels: local, global, and system.
By default, the local level is used if no configuration level is provided.
--local
To explicitly set a local value, add the parameter --local:
git config --local <configuration-name> <configuration-value>
This will set the value for that operating system user, only within that repository.
Local values can be found in the repository's git directory: .git/config
--global
To set a global value, add the parameter --global:
git config --global <configuration-name> <configuration-value>
This will set the value for every repository, for that operating system user.
Global values can be found in a file within the user's home directory:
- Unix and Unix-like systems - ~ /.gitconfig
- Windows - C:\Users\.gitconfig
--system
To set a system value, add the parameter --system:
git config --system <configuration-name> <configuration-value>
This will set the value for every repository, and for every user on that machine.
System-level configuration can be found in the following places:
- Unix and Unix-like systems - $(prefix)/etc/gitconfig
- Windows Vista and above - C:\ProgramData\Git\config
- Windows XP - C:\Documents and Settings\All Users\Application Data\Git\config