# Multiple user.name and user.email (possible feature request)

7 messages from 2010-04-18 to 2010-04-18. Participants: Eli Barzilay, Steven Michalske, Jeff King, Sverre Rabbelier.
Thread: https://gitlist.dev/t/23512

## Eli Barzilay, 2010-04-18 09:12

Subject: Multiple user.name and user.email (possible feature request)
Message-ID: <19402.52486.274010.66636@winooski.ccs.neu.edu>
URL: https://gitlist.dev/e/19402.52486.274010.66636%40winooski.ccs.neu.edu

```
Is there a way to have *no* default or some invalid default for the
name/email -- something that will make git refuse to create a commit?

For example, I'd be happy if I could put this in my global config:

  [user]
    name = "Eli Barzilay"
    email = "-"

and then have git barf at me when I try to commit with these settings,
since I prefer being forced to set the appropriate address for each
repository rather than deal with the alternative confusion (or just
accepting the limitations and always using the same name/email).

[When I tried to see if it's possible I was surprised to see that git
happily creates commits for "- <->" and even " <>".]

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

```

## Steven Michalske, 2010-04-18 18:16

Subject: Re: Multiple user.name and user.email (possible feature request)
Message-ID: <F5BFE3BD-7416-4F13-AF7F-0775E3234C92@gmail.com>
URL: https://gitlist.dev/e/F5BFE3BD-7416-4F13-AF7F-0775E3234C92%40gmail.com
In-Reply-To: <19402.52486.274010.66636@winooski.ccs.neu.edu>

```
On Apr 18, 2010, at 2:12 AM, Eli Barzilay wrote:

> Is there a way to have *no* default or some invalid default for the
> name/email -- something that will make git refuse to create a commit?
>
> For example, I'd be happy if I could put this in my global config:
>
>  [user]
>    name = "Eli Barzilay"
>    email = "-"
>
> and then have git barf at me when I try to commit with these settings,
> since I prefer being forced to set the appropriate address for each
> repository rather than deal with the alternative confusion (or just
> accepting the limitations and always using the same name/email).


Eli,

Just set the variable in the repository, not the global config.

i.e. drop the --global flag. So, in your repository:
git config user.email "that-repos-config"

I have three different email address for different repositories on my  
computer.  I have my global config set with my most common address,  
and the repositories with the less common email set locally in the  
repository.

Steve

```

## Jeff King, 2010-04-18 18:37

Subject: Re: Multiple user.name and user.email (possible feature request)
Message-ID: <20100418183759.GA11366@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20100418183759.GA11366%40coredump.intra.peff.net
In-Reply-To: <F5BFE3BD-7416-4F13-AF7F-0775E3234C92@gmail.com>

```
On Sun, Apr 18, 2010 at 11:16:34AM -0700, Steven Michalske wrote:

> >For example, I'd be happy if I could put this in my global config:
> >
> > [user]
> >   name = "Eli Barzilay"
> >   email = "-"
> >
> >and then have git barf at me when I try to commit with these settings,
> >since I prefer being forced to set the appropriate address for each
> >repository rather than deal with the alternative confusion (or just
> >accepting the limitations and always using the same name/email).
> 
> Just set the variable in the repository, not the global config.

I think the key is that he wants git to barf if he forgets to set the
repo-only config, instead of quietly using the global config.

Sine 1.7.0, git will complain loudly if you simply don't have your
identity set at all. There is no way to make it actually refuse the
commit, but the warning is quite gigantic and hard to miss:

  $ git config --global --unset user.name
  $ git config --global --unset user.email
  $ git commit -m foo
  [master 7c2a927] foo
   Committer: Jeff King <peff@c-71-185-130-222.hsd1.va.comcast.net>
  Your name and email address were configured automatically based
  on your username and hostname. Please check that they are accurate.
  You can suppress this message by setting them explicitly:

      git config --global user.name Your Name
      git config --global user.email you@example.com

  If the identity used for this commit is wrong, you can fix it with:

      git commit --amend --author='Your Name <you@example.com>'

   1 files changed, 1 insertions(+), 0 deletions(-)

So I expect that will serve Eli's purpose.

-Peff

```

## Sverre Rabbelier, 2010-04-18 18:43

Subject: Re: Multiple user.name and user.email (possible feature request)
Message-ID: <r2wfabb9a1e1004181143o7ebe2cf1t883ee4a12ba29a24@mail.gmail.com>
URL: https://gitlist.dev/e/r2wfabb9a1e1004181143o7ebe2cf1t883ee4a12ba29a24%40mail.gmail.com
In-Reply-To: <20100418183759.GA11366@coredump.intra.peff.net>

```
Heya,

On Sun, Apr 18, 2010 at 20:37, Jeff King <peff@peff.net> wrote:
> So I expect that will serve Eli's purpose.

If it does not, would a pre-commit hook work? If he sets some
recognizable string (such as not setting it) as email and install a
hook that barfs if it sees that?

-- 
Cheers,

Sverre Rabbelier

```

## Jeff King, 2010-04-18 18:55

Subject: Re: Multiple user.name and user.email (possible feature request)
Message-ID: <20100418185519.GA14331@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20100418185519.GA14331%40coredump.intra.peff.net
In-Reply-To: <r2wfabb9a1e1004181143o7ebe2cf1t883ee4a12ba29a24@mail.gmail.com>

```
On Sun, Apr 18, 2010 at 08:43:11PM +0200, Sverre Rabbelier wrote:

> On Sun, Apr 18, 2010 at 20:37, Jeff King <peff@peff.net> wrote:
> > So I expect that will serve Eli's purpose.
> 
> If it does not, would a pre-commit hook work? If he sets some
> recognizable string (such as not setting it) as email and install a
> hook that barfs if it sees that?

Yeah, that could work. It would do what he wants, but he would have to
have the hook set up. Which means he either needs to remember to
configure it in each repository (at which point he could just remember
to configure his identity), or he needs to point to a special init
template directory with the hook.

I think setting init.templatedir or GIT_TEMPLATE_DIR in the environment
would accomplish the latter.

-Peff

```

## Eli Barzilay, 2010-04-18 20:11

Subject: Re: Multiple user.name and user.email (possible feature request)
Message-ID: <19403.26467.273476.220670@winooski.ccs.neu.edu>
URL: https://gitlist.dev/e/19403.26467.273476.220670%40winooski.ccs.neu.edu
In-Reply-To: <F5BFE3BD-7416-4F13-AF7F-0775E3234C92@gmail.com>

```
On Apr 18, Steven Michalske wrote:
> 
> I have three different email address for different repositories on my  
> computer.  I have my global config set with my most common address,  
> and the repositories with the less common email set locally in the  
> repository.

(As already guessed) I really do want it to error instead of guessing.
My problem is that I'm very often checking out trees of one project
(and starting from today that svn-checkout has been replaced by a git
clone), and I will definitely get confused.  (It seems to me that this
is a common source of problems, leading to much flammage.)


On Apr 18, Jeff King wrote:
> 
> Sine 1.7.0, git will complain loudly if you simply don't have your
> identity set at all. There is no way to make it actually refuse the
> commit, but the warning is quite gigantic and hard to miss:
> [...]
> So I expect that will serve Eli's purpose.

Well, that would get closer, but I'd really prefer if there was a
do-not-use-me value I could set.  But in any case, even this is not
working for me -- digging through my environment, I found that I have
EMAIL set to my email, and so git guesses my name and doesn't produce
that huge response.

Worse, if I set up

  [user]
    name = ""
    email = ""

in my ~/.gitconfig (and make sure that I don't have EMAIL set), then
git still guesses the values -- without any warning.


On Apr 18, Jeff King wrote:
> On Sun, Apr 18, 2010 at 08:43:11PM +0200, Sverre Rabbelier wrote:
> > 
> > If it does not, would a pre-commit hook work? If he sets some
> > recognizable string (such as not setting it) as email and install
> > a hook that barfs if it sees that?
> 
> Yeah, that could work. It would do what he wants, but he would have
> to have the hook set up. Which means he either needs to remember to
> configure it in each repository (at which point he could just
> remember to configure his identity), or he needs to point to a
> special init template directory with the hook.
> 
> I think setting init.templatedir or GIT_TEMPLATE_DIR in the
> environment would accomplish the latter.

Yes, that sounds like it will work, and I'll do that.  But in general
this well beyond what most people would do.  If it was done as I
suggested (actually, how I thought it would behave), then this whole
thing would be easy even for people who are afraid of shell
programming...

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

```

## Eli Barzilay, 2010-04-18 20:53

Subject: Re: Multiple user.name and user.email (possible feature request)
Message-ID: <19403.28987.941803.339268@winooski.ccs.neu.edu>
URL: https://gitlist.dev/e/19403.28987.941803.339268%40winooski.ccs.neu.edu
In-Reply-To: <19403.26467.273476.220670@winooski.ccs.neu.edu>

```
On Apr 18, Eli Barzilay wrote:
> On Apr 18, Jeff King wrote:
> > I think setting init.templatedir or GIT_TEMPLATE_DIR in the
> > environment would accomplish the latter.
> 
> Yes, that sounds like it will work, and I'll do that.

... when 1.7.1 is out.  That's probably enough time for me to make a
mistake.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

```
