Manage Git Configuration with git config
This article explains how to check and change Git configuration settings such as your username and email address using the git config
command.
Types of Git Configuration Files (system, global, local)
Git has three configuration scopes:
Scope | Applies to | Example Location | Notes |
---|---|---|---|
system | All users and all repositories | /etc/gitconfig |
- |
global | All repositories for a user | ~/.gitconfig |
Located in the home directory |
local | A specific repository | repository/.git/config |
Located in the .git directory |
Git uses a priority system when multiple configurations exist for the same setting: local > global > system
. This means a local setting overrides the same one in the global or system scope.
In most cases, you don't need to worry about the physical location of these files. You can manage all of them using the git config
command, as explained below.
View and Modify Settings with git config
The git config
command is used to view, add, or change settings.
Common Configuration Options
Git provides many configurable settings. You can find a full list in the official documentation:
Here are some commonly used options:
user.name
: Your nameuser.email
: Your email addresscore.editor
: The text editor used for commit messagescolor.ui
: Controls color output (usually set toauto
)
Check a Specific Setting
To check the value of a specific configuration key, use:
$ git config <name>
Example:
$ git config user.email
example@example.com
This shows the effective value based on your current directory. If no value is set, nothing is displayed.
You can specify the scope explicitly:
$ git config --local <name>
$ git config --global <name>
$ git config --system <name>
Note: The --local
option works only inside a Git repository. If you run it outside a repository, you'll get an error:
$ git config --local user.email
fatal: --local can only be used inside a git repository
List All Configuration Settings
To list all effective settings, use the -l
or --list
option:
$ git config -l
$ git config --list
You can also list settings for a specific scope:
$ git config --local -l
$ git config --global -l
$ git config --system -l
Change a Setting
To change a configuration value, use:
$ git config <name> <value>
This changes the setting at the local level by default. To target global or system scope, use the appropriate option:
$ git config --global <name> <value>
$ git config --system <name> <value>
For example, to set your email address globally for all repositories:
$ git config --global user.email example@example.com
If you run the command without specifying a scope (which defaults to --local
) outside a Git repository, it will result in an error:
$ git config user.email example@example.com
fatal: not in a git directory
Edit Configuration Files Manually
You can also open the configuration files directly in an editor using the -e
or --edit
option:
$ git config -e
$ git config --global -e
$ git config --system -e
The file opens in the editor specified by the core.editor
setting. If no editor is configured, Git will use the system's default editor.