In this post, we will look at the different layers that can be configured. The layers are as follows:
- SYSTEM: This layer is system-wide and can be found in /etc/gitconfig
- GLOBAL: This layer is global for the user and can be found in ~/.gitconfig
- LOCAL: This layer is local to the current repository and can be found in .git/config
Step 1 : We will use the jgit repository for this example;
Step 2 : we can use the command git config --list to list configuration entries. This list is actually made from three different levels of configuration that Git offers: system-wide configuration, SYSTEM; global configuration for the user, GLOBAL; and local repository configuration, LOCAL.
Step 3 : We can also query a single key and limit the scope to one of the layers, by using the following command:
Step 4 : We can set the email address of the user to a different one for the current repository:
Step 5 : Now, listing the GLOBAL layer user.email will return john.doe@example.com, listing LOCAL will give john@example.com
When two or more values are specified for the same key, but on different layers, the lowest layer takes precedence. When a configuration value is needed, Git will first look in the LOCAL configuration. If not found here, the GLOBAL configuration is queried. If it is not found in the GLOBAL configuration, the SYSTEM configuration is used.
Step 6 : Instead of setting all the configuration values on the command line by the key value, it is possible to set them by just editing the configuration file directly. Open the configuration file in your favorite editor and set the configuration you need, or use the built-in git config -e repository to edit the configuration directly in the Git-configured editor. You can set the editor to the editor of your choice either by changing the $EDITOR environment variable or with the core.editor configuration target, for example: