git
git config
configuration
command line
tutorial

How can I remove an entry in global configuration with git config?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Removing a global Git config entry is usually a one-command operation, but the exact flag depends on whether the key appears once or multiple times. The safest workflow is to inspect the current value first, then remove either one matching entry or all matching entries explicitly.

Global Git configuration lives in your user-level Git config file, commonly ~/.gitconfig or ~/.config/git/config. The --global flag tells git config to operate on that scope rather than the current repository.

Remove a Single Global Entry

If the key has exactly one value, use --unset.

bash
git config --global --unset user.name

That removes the user.name setting from your global configuration. The same pattern works for any other key:

bash
git config --global --unset core.editor
git config --global --unset init.defaultBranch

This is the command most people want.

Inspect Before You Delete

Before removing a setting, check what is currently stored.

bash
git config --global --get user.name
git config --global --get core.editor
git config --global --list

If you want to know where a value came from, include --show-origin:

bash
git config --global --show-origin --get user.name

That is useful when you are not sure whether a value was set globally or locally.

Remove Keys That Appear More Than Once

Some Git keys may have multiple values. Common examples include repeated url.*.insteadOf entries or multiple fetch rules. In that case, --unset may complain because there is more than one match.

Use --get-all first:

bash
git config --global --get-all url.ssh://[email protected]/.insteadOf

Then remove all matching values with --unset-all:

bash
git config --global --unset-all url.ssh://[email protected]/.insteadOf

If you want to remove only one specific value for a multi-valued key, you can provide a value pattern:

bash
git config --global --unset-all remote.origin.fetch '^\\+refs/pull/\\*:refs/remotes/origin/pr/\\*$'

The last argument is treated as a regular expression, so escape carefully.

Edit the Global Config File Directly When Needed

Sometimes a key is malformed, repeated strangely, or easier to fix by hand. Git lets you open the global file in your configured editor:

bash
git config --global --edit

This is a good fallback when:

  • the key name is complicated
  • multiple similar entries exist
  • you want to clean up a block of related settings at once

Manual editing is especially helpful when you inherited a large config file and want to understand it rather than fire several destructive commands blindly.

Verify the Removal

After deleting a key, confirm the result:

bash
git config --global --get user.name

If the key is gone, Git usually exits with a non-zero status and prints nothing. You can also inspect the whole global configuration:

bash
git config --global --list

Verification matters because a local repository config may still define the same key, which can make it look as if the global removal “did not work.”

Global vs Local vs System

A very common source of confusion is scope. This command:

bash
git config --unset user.name

without --global operates on the repository configuration when run inside a repo. If you meant to remove the user-level setting everywhere, always include --global.

Likewise, if a value still appears after you removed it globally, it may be coming from:

  • the local repository config
  • the system config
  • an included config file

That is why --show-origin is so useful.

Common Pitfalls

The biggest mistake is forgetting --global and removing the repository-local value instead of the user-wide one.

Another issue is using --unset on a key that has multiple values. In that case, use --get-all to inspect the entries and --unset-all if you mean to remove them all.

People also sometimes remove a key and then immediately see the same effective value from another config scope. That is not a failed delete; it just means another file is still defining the key.

Finally, be careful with regex arguments to --unset-all. Git treats the optional value argument as a pattern, so shell escaping matters.

Summary

  • Use git config --global --unset key to remove a single global entry.
  • Use git config --global --unset-all key when the key has multiple values.
  • Inspect settings first with --get, --get-all, or --list.
  • Use --show-origin when you need to know which config file supplied a value.
  • If the command-line options become messy, open the file with git config --global --edit.

Course illustration
Course illustration

All Rights Reserved.