Skip to content

git config: invalid key format

Quick summary

You passed a malformed key to git config — the key must follow the format section.subsection.variable with valid characters.

Why this happens

  • The key contains invalid characters — only alphanumeric, hyphen, and dot are allowed in section and variable names

  • The section name is empty or the key has too few dots, e.g., 'user' instead of 'user.name'

  • The subsection name contains a dot without being quoted, confusing the key parser about section boundaries

Minimal example

✗ Broken code
git config user name 'John'  # error: invalid key: 'user name'
✓ Fixed code
git config user.name 'John'  # correct dot-separated key format

The key must use a dot to separate section from variable — a space makes git interpret it as an invalid key name.

How to diagnose

  • Check the key format — it should be section.variable or section.subsection.variable with no spaces

  • Run git config --list to see existing valid keys and compare the format with your intended key

  • Use git config --get <key> to test whether the key is recognized before setting it

How to fix

  • Correct the key to use the valid format: section.variable or section.subsection.variable with proper dot separation

  • Quote the entire key if the subsection contains special characters: git config 'user."full name".email' value

  • Use the --add flag with a fully qualified key to avoid ambiguity in section vs variable parsing

How to prevent

  • Follow the git config documentation for valid key naming conventions and always use section.variable format

  • Use git config --file to edit config files directly with a text editor for complex multi-dot keys

Related Resources

Related Glossary

Related Lessons

← Back to language