Handling Duplicates

What

Unlike standard key-value datatypes (like JSON or Python dictionaries), Git config files actually allow duplicate keys. You can map a single configuration key to multiple distinct values.

How

You can append multiple values to the same configuration key by using the --append flag:

# Add multiple values to the same key
git config set --append webflyx.ceo "Warren"
git config set --append webflyx.ceo "Carson"
git config set --append webflyx.ceo "Sarah"

If you try to use standard git config unset <key> on a key that has duplicate values, Git will throw an error because it doesn’t know which one to delete. To purge all occurrences of a duplicate key at once, you must use the --all flag:

# Delete all instances of a duplicate key
git config unset --all webflyx.ceo

Why

Allowing duplicate keys is essential for certain Git configurations. For example, Git uses duplicate keys to configure multiple refspecs when fetching from remote servers, or to define multiple URL paths that share the same configuration rules.

Summary

Git configuration files permit duplicate keys, which you can create using --append and must purge entirely using unset --all.