2

Is there a possibility of setting multiple user emails?

I'm trying to associate all future commits with several emails so that, for example, they could be found in GitHub/GitLab/(etc) UI by either of the emails, and also an existing GPG signature would still be applicable to that commit. Can this be done?


Let me also specify what I don't mean:

  • this is not about setting different emails for author and committer;
  • this is not about setting multiple authors and/or multiple committers;
  • this is not about setting different local user.email and global user.email;

Basically, I want to change this:

enter image description here

… into something like this:

enter image description here

3 Answers 3

3

Is there a possibility of setting multiple user emails? I'm trying to associate all future commits with several emails

Yes, Git's got a facility for this, the mailmap file. Its default location is as a committed .mailmap file, but you can configure it to be wherever you want, see git shortlog and git check-mailmap for the full details. So if you've got multiple emails, pick a primary one, write

Dima Parzhitsky <[email protected]> <[email protected]> <etc…>

to .mailmap and git will associate your primary name and email with all those email addresses.

so that, for example, they could be found in GitHub/GitLab/(etc) UI by either of the emails

There's no guarantee that every web frontend implements all of Git. The ones that don't implement Git's email mapping won't make the associations you list here. Git itself, though, will.

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

2 Comments

Thanks! Having this .mailmap file, will these emails be stored in the commits I make? Or this information will only exist in the file? Also, how does Git itself use this file?
Only in the file, you can use different files at any time. Git uses it to make its shortlogs, which do exactly what you want, attribute and present commits by author.
1

The short answer is no: a commit is supposed to have exactly one author, and one committer.

There apparently are some commits in some existing repositories that have more than one author, so git fsck diagnostics call this out as a separate error, which can be configured to be a warning instead of an error. This means that the checks for incoming commits (from git push operations to servers) can also call them out as warnings instead of errors.

If you were to make this a warning in every system you use—including all the hosting systems you use—you would gain the ability to create and transfer such commits. It does not seem like a particularly good plan overall, though.

3 Comments

Don't mean to be dismissive, but I'm not intending to set multiple people, just multiple emails for one person — be it a committer or author. Thanks for the response though!
Unfortunately the format for a commit requires exactly one email address per author or committer line, spelled out as author name <email> date offset with the angle brackets being literal here. (Try git cat-file -p HEAD to see one.) The angle brackets delimit the (single) email address.
Okay, I'll update the screenshot to make my intention clearer
0

It isn't possible to specify multiple email addresses for an author or committer in a single commit. The syntax you've proposed may (or may not) be accepted by Git, but it does not represent multiple email addresses. Since it does not match the production in RFC 5322, it fails to represent an email address at all. A real email address is permitted to contain spaces, but they must be quoted; this is just malformed.

GitHub and GitLab will not consider this syntax to match any valid email address at all because the part between the email address is supposed to represent exactly one email address according to the production in RFC 5322. Consequently, any such commit you make won't be associated with your account. Even if this syntax is accepted now, it may be rejected by Git or other tools in the future.

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.