Set your username and email in Git config

Fix Git’s ‘unable to auto-detect email’ error

Before you can issue a commit in Git, you must set the user.name and user.email properties.

Without the git config username and email, the attempted commit will fail, and the following error message will be returned:

fatal: unable to auto-detect email address
*** Please tell me who you are

How to configure Git username and email address

To permanently set the Git user.name and user.email address fields, simply issue the following two git config commands:

  1. git config --global user.email "[email protected]"
    
  2. git config --global user.name "cameronmcnz"

Just supply your own name and email address, and Git commits will no longer be a problem.

To verify that the git username and email address have been saved successfully, run the git config --list command and look for the user.name and user.email fields in the output.

show git config global

Verify your git config email and username settings with the –list switch.

Git config email concerns

Privacy minded people aren’t wont to just hand over their email address every time an app or service asks for it. Nobody wants to be spammed with unsolicited email. As such, some are leery to provide their email to Git config.

In the case of Git config, they shouldn’t be. The Git config email is not harvested for marketing purposes. Its only use is to provide substance to the author metadata that is attached to every commit.

Anyone looking through the Git log must be able to see who squashed a commit, performed a branch rebase, merged some code, added a Git tag or performed a commit. That’s all the git config user.name and user.email properties are used for. They’re not used as part of a marketing campaign.

Furthermore, the git config email is not validated, so you can give it an address that is made up or malformed.

The administrators on the DevOps team might be unimpressed by such antics, but at least you can perform your commits without anxiety over privacy concerns.

Local git config email and usernames

Git allows you to set variables at the system, global, local and workingtree level. If you want to use a special name or email address for a specific Git repo, you can set the git config email and username fields at the local or worktree scope. Worktree overrides local, local overrides global and global overrides system. This is the cascading nature of git config.

The command to set the local git config email and username is as follows:

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

It can be annoying hitting the fatal: unable to auto-detect email address error message when you’re anxious to commit code to the local repository. But it’s a problem that is easily fixed. Just add your email and username to git config and the problem will go away for good.

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close