0

I was trying to set up some git aliases and noticed a strange thing about git config:

$ git config user.name foo      # this stores the new name, ok
$ git config user.name bar baz  # this adds a 'name = bar' entry to the config, wtf?
$ git config user.name qux
warning: user.name has multiple values
error: cannot overwrite multiple values with a single value
Use a regexp, --add or --replace-all to change user.name.

I wonder why git stores multiple values in the 2nd case and when it can be useful?

2 Answers 2

2

The last "extra" parameter which caused your "wtf" is value_regex, see the documenation for details: https://git-scm.com/docs/git-config

Multiple values could be used e.g. for adding multiple fetch refspecs, see an example here: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec

Sign up to request clarification or add additional context in comments.

Comments

1

I have this in my Git config:

[include]
    path = ~/.gitconfig_user
    path = ~/.gitconfig_os

Which allows me to compose my configuration from chunks of Git config from external files. I'm guessing, for consistency, Git allows you to specify multiple values for any key, but they'll only make sense for a specific set of consumers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.