Understanding Git Configuration Files
Understanding Git Configuration Files
Git uses configuration files to store settings that control the behavior and appearance of the version control system. These configuration files are organized in three levels: repository-level, user-level, and system-level configurasions.
The priority order for these configuration levels is repository > user > system. Git provides the git config command to manage these configuration variables.
Configuration File Locations
Repository-level configuration is stored in ./.git/config within the repository. This applies only to the specific repository. Use the --local flag to read from or write to this file, which is the default behavior when working within a repository.
User-level configuration resides in ~/.gitconfig or ~/.config/git/config depending on your system. On Windows, this translates to C:\Users\$USER\.gitconfig. This configuration applies to the current user across all repositories. Use the --global flag to access this file.
System-level configuration is located at /etc/gitconfig within the Git installation directory. This contains default settings for all users and repositories on the system. Use the --system flag to modify this file. Note that modifying system-level configuration requires administrator or superuser privileges.
To view all configuration settings along with their source files, run:
git config --list --show-origin
Querying Configuration Information
Format: git config [--local|--global|--system] --list
The git config --list command displays the final computed configuration by merging all three configuration files. Git resolves conflicts by using the last value found for each variable.
$ git config --list
user.name=John Doe
user.email=john@example.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...
You may encounter duplicate variible names because Git reads from multiple files (such as /etc/gitconfig and ~/.gitconfig). In such cases, Git uses the most recently defined value for each key.
To check a specific configuration value, use:
$ git config user.name
John Doe
Modifying Configuration Files
Editing Configuration Files
Format: git config [--local|--global|--system] --edit
This command opens the configuration file in your configured text editor. If you haven't set a preferred editor, Git will use your system's default editor.
To set a different text editor, such as Emacs:
$ git config --global core.editor emacs
On Windows, you must provide the full path to the executable. For example, to configure Notepad++ (32-bit version):
$ git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Adding Configuration Entries
Format: git config [--local|--global|--system] --add key value
This command adds a new configuration key with the specified value to the target configuration file.
Removing Configuration Entries
Format: git config [--local|--global|--system] --unset key
This command removes the specified configuration key from the target configuration file.
Accessing Help
For comprehensive documentation about configuration options, use:
git help config