169

I'm trying to commit some changes as a different user, but i do not have a valid email address, following command is not working for me:

git commit --author="john doe" -m "some fix"
fatal: No existing author found with 'john doe'

I have the same problem when trying to commit with only an email address

git commit --author="[email protected]" -m "some fix"
fatal: No existing author found with '[email protected]'

On the GIT man pages for the commit command it says i can use the

standard A U Thor <[email protected]> format

For the --author option.

Where is this format defined ? what does A and U stand for ? how do i commit for a different user with only a username or only an email?

3
  • 3
    A U doesn't stand for anything, it's just an example: A U Thor => AUThor => Author. You can specify anything you want as a name. Commented Jul 20, 2012 at 12:56
  • 1
    I know that A U Thor forms Author, i was wondering if there was any significance in the separation. Commented Jul 20, 2012 at 13:25
  • 1
    Related: Can I specify multiple users for myself in .gitconfig?.
    – user456814
    Commented May 19, 2014 at 1:42

10 Answers 10

195

The minimal required author format, as hinted to in this SO answer, is

Name <email>

In your case, this means you want to write

git commit --author="Name <email>" -m "whatever"

Per Willem D'Haeseleer's comment, if you don't have an email address, you can use <>:

git commit --author="Name <>" -m "whatever"

As written on the git commit man page that you linked to, if you supply anything less than that, it's used as a search token to search through previous commits, looking for other commits by that author.

5
  • 29
    Just found out that if you don't have an email address you can also just type "name <>" , to explicitly leave it blank instead of entering bogus. Commented Jul 20, 2012 at 13:29
  • 3
    If you'd use "name <>", and git commit --amend after, it will fail with invalid ident error; so just don't
    – sanmai
    Commented Jun 16, 2016 at 8:54
  • 11
    Apparently even when using that option, you still need to have set user.email and user.name in your git config, otherwise git complains.
    – qwertzguy
    Commented Dec 16, 2016 at 1:07
  • How do I add a file as a different user for my first commit ? I will use the commit command after that.
    – MasterJoe
    Commented Aug 7, 2020 at 22:39
  • for me the --author ocmmand never works and writes that author matches no existing author or something, this works though git -c user.name="name" -c user.email="email" commit -m "message"
    – user151496
    Commented Apr 2 at 14:23
68

The specific format is:

git commit --author="John Doe <[email protected]>" -m "Impersonation is evil." 
3
  • 2
    Why doesn't it require password of John Doe if you commit for his name?
    – Narek
    Commented Mar 17, 2015 at 6:28
  • 4
    @Narek What would that be in this context?
    – pmr
    Commented Mar 20, 2015 at 0:28
  • This apparently no longer works? On git version 2.43.0 I get "Committer identity unknown" Commented Dec 27, 2023 at 2:39
51

The --author option doesn't bypass reading the invoking user's personality:

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

This does:

git -c user.name='A U Thor' -c [email protected] commit

Tip: For the purpose of separating work- and private git personalities, Git 2.13 supports directory specific configuration: You no longer need to wrap git with these options to get that.

5
  • 6
    This is the only one that worked for me. Note the order is important. git commit -c user.name="j bloggs" -am "message" gives an error fatal: Option -m cannot be combined with -c/-C/-F
    – Martin
    Commented Jul 10, 2020 at 9:14
  • 5
    @Martin Yes, because the -c flag pertains to the git command proper and not the commit subcommand (which btw has a different -c flag)
    – zerzevul
    Commented Jan 5, 2021 at 17:30
  • 4
    This is the real answer. The rest suggesting --author are not helpful at all because user name and email are still required. Commented Mar 9, 2022 at 11:20
  • This should be the accepted answer. I am on GitHub Codespaces, where several different users could in principle use the same shell to make commits. Setting the global or repository author is thus prone to misattributing the individual commit author. Setting -c user.name inline is preferable, and this is the only way to do it. Commented Dec 27, 2023 at 2:41
  • It looks like I'm mistaken! git -c ... will write those inputs to ~/.gitconfig i.e. it's having the same effect as running git config --global. To get a temporary user, then, it seems we'd need to follow up this command by then deleting the entries from ~/.gitconfig. Commented Dec 27, 2023 at 9:30
43

The

standard A U Thor <[email protected]> format

Seems to be defined as followed: ( as far as i know, with absolutely no warranty )

A U Thor = required username

  • The separation of the characters probably indicates that spaces are allowed, it could also be resembling initials.
  • The username has to be followed by 1 space, extra spaces will be truncated

<[email protected]> = optional email address

  • Must always be between < > signs.
  • The email address format isn't validated, you can pretty much enter whatever you want
  • Optional, you can omit this explicitly by using <>

If you don't use this exact syntax, git will search through the existing commits and use the first commit that contains your provided string.

Examples:

  1. Only user name

    Omit the email address explicitly:

    git commit --author="John Doe <>" -m "Impersonation is evil."
    
  2. Only email

    Technically this isn't possible. You can however enter the email address as the username and explicitly omit the email address. This doesn't seem like it's very useful. I think it would make even more sense to extract the user name from the email address and then use that as the username. But if you have to:

    git commit --author="[email protected] <>" -m "Impersonation is evil." 
    

I ran in to this when trying to convert a repository from mercurial to git. I tested the commands on msysgit 1.7.10.

13

Just supplement:

git commit --author="[email protected] " -m "Impersonation is evil."

In some cases the commit still fails and shows you the following message:

*** Please tell me who you are.

Run

git config --global user.email "[email protected]" git config --global user.name "Your Name"

to set your account's default identity. Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got xxxx)

So just run "git config", then "git commit"

1
  • This is what I needed. I have separate username and email for a corporate GitHub and the public GitHub. I needed to set my current repo to use my public GitHub username and email so that I could push my changes without exposing a private email. Commented Aug 21, 2019 at 16:44
9

Format

A U Thor <[email protected]>

simply mean that you should specify

FirstName MiddleName LastName <[email protected]>

Looks like middle and last names are optional (maybe the part before email doesn't have a strict format at all). Try, for example, this:

git commit --author="John <[email protected]>" -m "some fix"

As the docs say:

  --author=<author>
       Override the commit author. Specify an explicit author using the standard 
       A U Thor <[email protected]> format. Otherwise <author> is assumed to 
       be a pattern and is used to search for an existing commit by that author 
       (i.e. rev-list --all -i --author=<author>); the commit author is then copied 
       from the first such commit found.

if you don't use this format, git treats provided string as a pattern and tries to find matching name among the authors of other commits.

1
  • There's no such thing as FirstName MiddleName LastName. See this. Commented Jul 20, 2012 at 12:59
6
git -c "user.name={{ name }}" -c "user.email={{ email }}" commit -m "{{ message }}"

where {{ }} indicates YOU put the value

1

Open Git Bash.

Set a Git username:

$ git config --global user.name "name family" Confirm that you have set the Git username correctly:

$ git config --global user.name

name family

Set a Git email:

$ git config --global user.email [email protected] Confirm that you have set the Git email correctly:

$ git config --global user.email

[email protected]

1

It is all dependent on how you commit.

For example:

git commit -am "Some message"

will use your ~\.gitconfig username. In other words, if you open that file you should see a line that looks like this:

[user]
    email = [email protected]

That would be the email you want to change. If your doing a pull request through Bitbucket or Github etc. you would be whoever you're logged in as.

0

An alternative if the concern is to hide the real email address...If you are committing to Github you don't need a real email you can use <username>@users.noreply.github.com

Regardless of using Github or not, you probably first want change your committer details (on windows use SET GIT_...)

GIT_COMMITTER_NAME='username' 
GIT_COMMITTER_EMAIL='[email protected]'

Then set the author

git commit --author="username <[email protected]>"

https://help.github.com/articles/keeping-your-email-address-private

1
  • Unlike all of the other solutions, this works when you haven't initialized user.email/user.name initially.
    – Andy
    Commented Feb 27, 2020 at 19:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.