32

working on a lab machine which has a shared login. don't want to set global git config parameters.

git commit --author="username <email>" 

This used to work on older git versions. now it produces this error:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  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 'blah@blah.(none)')

Any thoughts?

richmb
  • 1,495
  • 2
  • 15
  • 20

5 Answers5

24

What if you set the git config info just for the current repository?

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

EDIT Based on OP comment a possible solution is:

GIT_AUTHOR_EMAIL="you@email.com" && GIT_AUTHOR_NAME="Your Name" && git commit
Aguardientico
  • 7,641
  • 1
  • 33
  • 33
8

Another solution is, to set the identity just for one run of git commit and make use of the -c option of git.

git -c user.name="Your Name" -c user.email="you@example.com" commit -m "message"

My scenario is to run a docker container where I'm a user (not being root) in the container, which has no write permission on its home directory. The image is docker.io/alpine/git.

$ docker run -u 1004:1005 -it --rm --entrypoint=/bin/sh docker.io/alpine/git 
~ $ git config --global user.email "you@example.com"
error: could not lock config file /git/.gitconfig: Permission denied
white_gecko
  • 4,808
  • 4
  • 55
  • 76
5

First, With Git 2.29 (Q4 2020), the error message is clearer.

See commit 9ed104e (21 Aug 2020) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit e9bd00a, 31 Aug 2020)

ident: say whose identity is missing when giving user.name hint

If user.name and user.email have not been configured and the user invokes:

git commit --author=...  

without specifying the committer identity, then Git errors out with a message asking the user to configure user.name and user.email but doesn't tell the user which attribution was missing.

This can be confusing for a user new to Git who isn't aware of the distinction between user, author, and committer.

Give such users a bit more help by extending the error message to also say which attribution is expected.

The error message will clearly state:

Author identity unknown
# or
Committer identity unknown

Second, from OP's comment:

Other people use the machine and the same repo. I guess I could set up the git config and then remove the configuration when I'm done

You can wrap the git command and forcing each used to identify themselves (once per shell session).
See "Best pracitces for multi-developer Git for single user application" and my project VonC/gitw.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
3

In Terminal:

  • git config --global user.email "nive54@gmail.com"
  • git config --global user.name "Nivetha"

Note:

GitHub registered email --> nive54@gmail.com

Your system name --> Nivetha (Refer to thispc->properties for this.)

Olivia Stork
  • 4,660
  • 5
  • 27
  • 40
Nivetha
  • 41
  • 1
0

For those who are working on Gitbash.

The steps include, setting up a username and then providing an email address, so that you can commit the changes, when you use $git commit -m "message to display" command.

For username:

$git config --global user.name "xyz"

For email address:

$git config --global user.email anything@gmail.com 

[Do not use quotes while writing email]

So, the next time you use this command, $ git commit -m "abc.txt file added" Successful changes are made.

EDTA
  • 1