git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git config multiple values

From
Aaleksander.baranowski <aleksander.baranowski@yahoo.pl>
Date
Oct 6, 2017, 16:57 UTC
Message-ID
<07ab076b-e1c6-8731-4501-17459bdff005@yahoo.pl>
In-Reply-To
<20171006143219.4bn63aoenluc77fd@sigill.intra.peff.net>
Hi!,
Thank you very much for descriptive answer.

You are absolutely right. I should read manual more carefully! Still it's quite odd interface. Thank you for your time.

Bests, Alex

On 10/06/2017 04:32 PM, Jeff King wrote:
Show 69 quoted lines
> On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:
> 
>> I'm currently using git version 2.14.2. There is possible to put
>> multiple values into same variable with git config.
> 
> Yep, your examples should behave the same even with older versions.
> 
>> Case 1:
>> # git config --global user.name Foo - returns 0
>> # git config --global user.name Bar - returns 0 and replace Foo to Bar
>> # git config --global user.name Foo - returns 0 and replace Bar to Foo
> 
> This is all as expected. You're hitting the first case in the manpage
> synopsis here (I snipped the uninteresting options):
> 
>   git config name [value [value_regex]]
> 
> So you're doing:
> 
>   git config name value
> 
> which replaces any existing key by default. You could also do:
> 
>   git config --add name value
> 
> to add without replacing (if you had a config key that takes multiple
> values).
> 
>> Case 2:
>> # git config --global user.name Foo - returns 0
>> # git config --global user.name Foo2 Bar - returns 0 and put second name
> 
> Here you're doing:
> 
>   git config name value value_regex
> 
> So we're replacing any values which match the regex "Bar" (and there are
> none), and leaving others intact. Hence after this you will have two
> user.name values.
> 
> If you wanted a name with two strings, you'd have to quote the string
> from the shell to leave it as a single argument:
> 
>   git config user.name "Foo2 Bar"
> 
>> # cat ~/.gitconfig
>> [user]
>> 	email = aleksander.baranowski@yahoo.pl
>> 	name = Foo
>> 	name = Foo2
> 
> Right, this is what I'd expect.
> 
>> # git config --global user.name Foo - return 5 and message
>> "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."
> 
> And this, too (though I forgot we had such a safety check).
> 
>> It's just an opinion, but this behaviour is no consistent for me.
>>
>> If it's not the bug it's a feature just let me know.
> 
> It's a feature, though I agree that git-config is rather baroque. We're
> mostly stuck with it for reasons of backwards compatibility, though.
> 
> -Peff
> 
Previous: Jeff KingNext: Jonathan Nieder
Message 3 of 6 in “Git config multiple values”
  1. aleksander.baranowskiOct 6, 2017
  2. Jeff KingOct 6, 2017
  3. aleksander.baranowskiOct 6, 2017
  4. Jonathan NiederOct 6, 2017
  5. Jeff KingOct 6, 2017
  6. Andreas HeidukOct 6, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.