Understanding the Three Levels of Git Config: Local, Global, and System

Prakhar Yadav
2 min readJun 20, 2023

--

Introduction:

Git, the popular version control system, provides three levels of configuration: local, global, and system. Each level serves a specific purpose and allows you to customize settings based on different scopes. In this blog post, we will dive into each level of Git config, explore their significance, and provide examples to help you understand their practical applications.

1. Local Git Config:

This is the default level for git config. The local level of Git config is specific to a particular repository. It allows you to set configurations that are relevant only to that repository. This level takes precedence over global and system configurations. Local configurations are stored in the `.git/config` file within the repository.

Example: To set the user name for a specific repository, use the following command:
```
git config user.name “Your Name”
```
This command sets the user name to “Your Name” only for that repository.

2. Global Git Config:

The global level of Git config applies settings to the currently logged-in user across all repositories. It enables you to maintain consistent configurations for your personal preferences. Global configurations are stored in the `~/.gitconfig` file in your home directory.

Example: To set the user name globally, use the following command:
```
git config — global user.name “Your Name”
```
This command associates the name “Your Name” with your user account, which will be used as the author information for commits made across different repositories.

3. System Git Config:

The system level of Git config controls settings for all users and repositories on your computer. It applies globally and affects all repositories, regardless of the logged-in user. System configurations are stored in the `/etc/gitconfig` file and usually require administrative privileges to modify.

Example: To set the user name at the system level, use the following command:
```
git config — system user.name “Your Name”
```
This command sets the user name to “Your Name” for all users and repositories on the system.

Managing Configurations:

To remove or unset a configuration option, you can use the ` — unset` flag with the appropriate level. For example, to remove the global user name configuration, you would run:
```
git config — global — unset user.name
```
Similarly, you can unset other configuration options like user email, or any other configuration option.

Conclusion:

Understanding the three levels of Git config — local, global, and system — provides you with the flexibility to customize your Git environment based on different scopes. Local configurations are specific to a repository, global configurations are applied to the currently logged-in user, and system configurations affect all users and repositories on the computer.

Happy coding and configuring!

--

--