Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent Git from auto-detecting user.email?

I don't have any global user.email or global user.name setup on purpose.

I like to set my user.email and user.name per repo by using the git config user.email and git config user.name commands.

On macOS with git version 2.17.0, if I forget to set user.email or user.name for a repo on my Mac, when I run git commit I get this error:

*** 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 'lone@mymac.(none)')

This is good because it reminds me that I need to set the user.email and user.name config for my repo.

But on my Debian system with git version 2.11.0, if I forget to set user.email or user.name for a repo, whe I run git commit it commits the change with Lone Learner <lone@mydeb> as the author. I am guessing that it auto-detects user.name from /etc/passwd and auto-detects user.email as <user>@<host>.

I would like to disable this auto-detection of user.name and user.email on Debian or any system Git is on. If I have not explicity set user.name or user.email I want Git to fail in the manner it fails as shown in the Mac example above or in some other way. Is there anyway to achieve this either using ~/.gitconfig or some other way?

like image 478
Lone Learner Avatar asked Jul 08 '18 07:07

Lone Learner


People also ask

Why does git need my email?

It is explained in the Git SCM ebook: http://git-scm.com/book/en/v1/Getting-Started-First-Time-Git-Setup. And because pull request could be made by sending patch by email. This way you are sure that people could communicate together (and email is the simplest thing that guarantee the identity of someone...)

How do you omit a global to set the identity only in this repository?

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.” Code Answer.


1 Answers

Since Git 2.8, use:

git config --global user.useConfigOnly true

That will avoid the "autodetection" done on your Debian environment.
See more at "How do I make git block commits if user email isn't set?".

like image 181
VonC Avatar answered Nov 15 '22 05:11

VonC