54

I used git for the first time and I set my user name and user mail. The commands I used are below:

git config --global user.email "bob@example.com"
git config user.email "bob@example.com"
git config --global user.name "bob"
git config user.name "bob"

When I run git commit --author "bob" , I got an error fatal: No existing author found with 'bob'. How can I set user name and email?

Evan Porter
  • 2,987
  • 3
  • 32
  • 44
  • 1
    You wouldn't normally want to set your user/email anywhere but in the global config, so the commands where you don't have "--global" probably aren't what you want. Once you have done that just use `git commit` without "--author" – Andrew C Oct 11 '14 at 20:09
  • I tried without "--author" and it was ok. thanks for your help –  Oct 11 '14 at 20:19
  • 1
    This is an example of why git is not user-friendly. – A T - student Jul 15 '15 at 18:19
  • 1
    the format should be 'Bob ' – Kennedy Nyaga Sep 01 '17 at 09:45
  • It can also happen when you don't have permission to push to the repository. Make sure to check if you are added as a committer to the repo. – Teja Dec 13 '18 at 04:24

4 Answers4

68

You should stop using --author each time you commit, and instead configure an author with git config. Once you've done so, you can type git commit and the author will be pulled from your .gitconfig file.

If you want to give --author a name to use for authoring the commit, you need to use

bob <bob@example.com>

not just bob. If your author string doesn't match the user <user@example.com> format, Git assumes you've given it a search pattern, and it will try to find commits with matching authors. It will use the first found commit's user <user@example.com> as the author.

Black
  • 18,150
  • 39
  • 158
  • 271
user229044
  • 232,980
  • 40
  • 330
  • 338
  • 2
    In Android Studio for private project with permission to User, you need to add `User ` to the author section when commit. – QuartZ Apr 05 '18 at 03:00
22

This command will do the trick:

git commit --amend -C HEAD --reset-author
kenorb
  • 155,785
  • 88
  • 678
  • 743
Ivan Voroshilin
  • 5,233
  • 3
  • 32
  • 61
7

Note: starting with Git 2.3.1+ (Q1/Q2 2015), the error message will be more explicit.
See commit 1044b1f by Michael J Gruber (mjg):

commit: reword --author error message

If an --author argument is specified but does not contain a '>' then git tries to find the argument within the existing authors; and gives the error message "No existing author found with '%s'" if there is no match.

This is confusing for users who try to specify a valid complete author name.

Rename the error message to make it clearer that the failure has two reasons in this case.

The solution remains to have the config user.name and user.email properly set, but for the case where --author is used, at least the expected argument is now clearer.

So run:

git add --all ; git commit -m "$git_msg" \
    --author "First Last <first.last@company.com>"; git push
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

For my experience, don't forget <> The correct format is

git commit --amend --author="bob <bob@example.com>"`

But

git commit --amend --author="bob bob@example.com"

will show is not 'Name <email>' and matches no existing author

Luke
  • 19
  • 3