# Git config multiple values

6 messages from 2017-10-06 to 2017-10-06. Participants: aleksander.baranowski, Jeff King, Jonathan Nieder, Andreas Heiduk.
Thread: https://gitlist.dev/t/46925

## aleksander.baranowski, 2017-10-06 11:10

Subject: Git config multiple values
Message-ID: <4b848032-e8b6-be67-58d9-e3fcc2c11853@yahoo.pl>
URL: https://gitlist.dev/e/4b848032-e8b6-be67-58d9-e3fcc2c11853%40yahoo.pl

```
Hi,

I'm currently using git version 2.14.2. There is possible to put
multiple values into same variable with git config.

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

Case 2:
# git config --global user.name Foo - returns 0
# git config --global user.name Foo2 Bar - returns 0 and put second name
# cat ~/.gitconfig
[user]
	email = aleksander.baranowski@yahoo.pl
	name = Foo
	name = Foo2
# 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."

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.

Bests,
Alex

```

## Jeff King, 2017-10-06 14:32

Subject: Re: Git config multiple values
Message-ID: <20171006143219.4bn63aoenluc77fd@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20171006143219.4bn63aoenluc77fd%40sigill.intra.peff.net
In-Reply-To: <4b848032-e8b6-be67-58d9-e3fcc2c11853@yahoo.pl>

```
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

```

## aleksander.baranowski, 2017-10-06 16:57

Subject: Re: Git config multiple values
Message-ID: <07ab076b-e1c6-8731-4501-17459bdff005@yahoo.pl>
URL: https://gitlist.dev/e/07ab076b-e1c6-8731-4501-17459bdff005%40yahoo.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:
> 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
> 

```

## Jonathan Nieder, 2017-10-06 17:25

Subject: Re: Git config multiple values
Message-ID: <20171006172530.GV19555@aiede.mtv.corp.google.com>
URL: https://gitlist.dev/e/20171006172530.GV19555%40aiede.mtv.corp.google.com
In-Reply-To: <20171006143219.4bn63aoenluc77fd@sigill.intra.peff.net>

```
Hi,

Jeff King wrote:
> On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:

>> 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.

This feels like a dodge.  Can we make a list of what is baroque here,
with an eye to fixing it?  E.g. if we introduce a new --set option,
then what should its semantics be, to be more intuitive?

Thanks,
Jonathan

```

## Jeff King, 2017-10-06 17:28

Subject: Re: Git config multiple values
Message-ID: <20171006172805.2udoryqelqbim5eg@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20171006172805.2udoryqelqbim5eg%40sigill.intra.peff.net
In-Reply-To: <20171006172530.GV19555@aiede.mtv.corp.google.com>

```
On Fri, Oct 06, 2017 at 10:25:30AM -0700, Jonathan Nieder wrote:

> Jeff King wrote:
> > On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:
> 
> >> 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.
> 
> This feels like a dodge.  Can we make a list of what is baroque here,
> with an eye to fixing it?  E.g. if we introduce a new --set option,
> then what should its semantics be, to be more intuitive?

Maybe baroque isn't the right word. But changing the function of a
command drastically based on the number of arguments seems like a source
of confusion.

I'm fine if somebody wants to champion a new "--set" option, but frankly
I'm not sure it's worth the pain at this point.

-Peff

```

## Andreas Heiduk, 2017-10-06 18:58

Subject: Re: Git config multiple values
Message-ID: <962cbecd-4be1-f041-30e3-cc4cd19310d0@gmail.com>
URL: https://gitlist.dev/e/962cbecd-4be1-f041-30e3-cc4cd19310d0%40gmail.com
In-Reply-To: <20171006172530.GV19555@aiede.mtv.corp.google.com>

```
Hi,

Am 06.10.2017 um 19:25 schrieb Jonathan Nieder:
> Hi,
> 
> Jeff King wrote:
>> On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:
> 
>>> 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.
> 
> This feels like a dodge.  Can we make a list of what is baroque here,
> with an eye to fixing it?  E.g. if we introduce a new --set option,
> then what should its semantics be, to be more intuitive?


My reading of the manual for 

	git config --global user.name Foo2 Bar

is this:

       Multiple lines can be added to an option by using the --add option.

Does not apply here - no `--add` option, so no new value should be added.

       If you want to update or unset an option which can occur on multiple
       lines, a POSIX regexp value_regex needs to be given. 

does not apply: First: no "--unset" variant is used here leaving only "update".
Second: before that command there is only one value.

       Only the existing values that match the regexp are updated or unset.

Since "Two" does not match the previous value and `update` is the only 
described case left I'd expect that the command changes nothing.I don't
understand how the description allows `git config` to add a new value,
because the manual talks about "update" twice, nothing about adding.


Confused
--Andreas

```
