On This Page

Git Config: Set, List, and Locate Settings

Quick answer: Use git config --global for settings shared by your user account, and git config --local for a setting that belongs only to the current repository. To see the value Git resolves inside a repository, run git config <key>. To find where it came from, add --show-origin --show-scope.

Set your commit name and email

Git records a name and email address in each new commit. They are commit metadata, not your GitHub password or login name. Set a default identity for your operating-system account with:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Check the values Git will use from the current repository:

git config user.name
git config user.email

If you are outside a repository, those unscoped reads may not find repository-local settings. The global values can be checked explicitly:

git config --global user.name
git config --global user.email

Use your own name and an email address you are comfortable associating with commits. If you need to correct the author details on commits that already exist, see How to Change a Git Commit Author; changing config affects future commits, not past ones.

Git config file locations and scopes

Git reads settings from several files. The two locations most people need are ~/.gitconfig for global settings and .git/config inside a repository for local settings. More specific file-based settings usually override broader ones when the same key is defined more than once.

ScopeApplies toTypical locationUseful when
SystemEvery user and repository on the machineGit’s system config, commonly /etc/gitconfig on LinuxAn administrator sets machine-wide defaults
GlobalRepositories used by your operating-system account~/.gitconfig or $XDG_CONFIG_HOME/git/config; on Windows, commonly %USERPROFILE%\.gitconfigYou want your usual name, email, editor, or defaults everywhere
LocalOne repository.git/config inside that repositoryA work or project repository needs an exception to your global setting
WorktreeOne linked working treeA worktree-specific config file when the feature is enabledOne checkout of a repository needs its own setting

For writes, --global selects the user-level file and --local selects the current repository’s .git/config. With no scope flag, a write normally targets the local repository config; run it from inside a repository. --system and --worktree are for cases where you specifically need those scopes.

For example, set a different email just for the repository you are currently in:

git config --local user.email "work@example.com"

That local value takes priority over the global email in this repository. Other repositories continue to use the global value unless they have their own local setting.

List settings and find their source

To list the values Git reads in the current context:

git config --list

The output can include the same key more than once when multiple scopes define it. To see both the scope and the file that supplied each entry, run:

git config --list --show-origin --show-scope

To list only one scope, use an explicit flag:

git config --global --list
git config --local --list

To inspect one resolved value and identify its source, run this inside the repository where the value matters:

git config --show-origin --show-scope user.email

This is the quickest way to diagnose “why is Git using that email?” A repository-local value may be overriding the global one. You can also open a file directly in your configured editor with git config --global --edit or, from inside a repository, git config --local --edit.

Privacy note: Configuration output may contain private repository URLs or other sensitive values. Review it before sharing a full git config --list transcript publicly.

Change or remove a setting

To update a global value, set it again with the same key:

git config --global user.email "new-address@example.com"

To remove a value, name the scope where it is stored:

git config --global --unset user.email

If Git still reports a value afterward, another scope may define the same key. Inspect it with git config --show-origin --show-scope user.email. Removing the global value does not remove a separate local override, and removing a local value does not change the global file.

Common Git config questions

What does git config --list do?

It prints configuration entries Git reads for the current command context. If settings are defined in multiple scopes, the list can show multiple entries for a key. Use --show-origin --show-scope to see where each entry came from; use git config <key> to ask Git for the value it resolves in the current repository.

Where is the global Git config file?

It is commonly ~/.gitconfig on macOS and Linux and %USERPROFILE%\.gitconfig on Windows. Git can also use $XDG_CONFIG_HOME/git/config; git config --global --list --show-origin shows the file actually used on your machine.

Why does a local value differ from my global value?

The repository’s local config can override a global setting for that repository. Run git config --show-origin --show-scope <key> from the repository to see which value is winning.

Does changing user.email rewrite old commits?

No. It changes the identity Git records on future commits. Existing commit objects keep their recorded author and committer information unless you deliberately rewrite history. For that separate task, follow the commit-author guide.

Go further

Test Your Knowledge

Loading quiz…