6

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 "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 '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?

Lone Learner
  • 18,088
  • 20
  • 102
  • 200
  • duplicates: https://stackoverflow.com/q/19821895/1256452, https://stackoverflow.com/a/12292895/6309 – torek Jul 08 '18 at 07:20
  • @torek Thank you for sharing the duplicates. I did try to search for existing questions on this topic before posting this question but the search terms I was trying (example: git prevent auto detect user.email) did not help. – Lone Learner Jul 08 '18 at 08:20
  • Well, duplicates aren't bad, and are sometimes (as in this case) even good. See meta-discussion here: https://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled I wasn't sure if I should close this, much less which one(s) to pick as the dupe... :-) – torek Jul 08 '18 at 12:10

1 Answers1

8

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?".

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