Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Git: fatal: unable to auto-detect email address

A commit needs an author identity. Containers and fresh installs have no user.email, so Git guesses from the OS user and refuses to continue.

~5 min readGit
#git#configuration#ci#commit-author
Bold white headline reading NO GIT IDENTITY beside a cyan commit crate with an amber blank author card.

Introduction & Quick Summary

The first commit in a fresh container or a new machine stops with:

code
*** 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 'root@f3c9a1b2c4d5.(none)')

Quick answer: a commit records an author name and email, and Git refuses to invent them. It looks for user.email and user.name in its configuration, then for an EMAIL environment variable, then tries to build an address from the operating-system user and hostname — hence the root@...(none) string. When that guess is not a valid address, it stops.

bash
git config --global user.name "Ryu" git config --global user.email "ryu@example.com"

For a container, CI job or one-off script, set the identity where it belongs instead of changing the machine's global config:

bash
git -c user.name="CI Bot" -c user.email="ci@example.com" commit -m "build: regenerate lockfile"

The rest of this guide covers where Git looks for the identity and in what order, how to keep a work identity and a personal one on the same machine, how to fix commits that were already created with the wrong author, and why containers hit this while the developer's laptop does not.

Core Mechanics, Signatures & Reproducible Setup

Git reads configuration from several scopes. For each key the most specific value wins:

bash
git config --list --show-origin # file:/etc/gitconfig core.autocrlf=input # file:/home/ryu/.gitconfig user.name=Ryu # file:.git/config user.email=ryu@work.example.com

The four scopes are system (/etc/gitconfig), global (~/.gitconfig or $XDG_CONFIG_HOME/git/config), local (.git/config) and worktree, plus -c key=value on the command line. A commit needs user.name and user.email; if the email cannot be resolved, the commit aborts before any object is written.

bash
# the identity Git would use in this repository git var GIT_AUTHOR_IDENT # Ryu <ryu@example.com> 1701234567 +0900 # what is set, and where git config --get user.name git config --get user.email git config --show-origin --get-regexp '^user\.'

A reproducible failure, useful for understanding the message:

docker run --rm -it alpine/git sh git init demo && cd demo git commit --allow-empty -m "first" # fatal: unable to auto-detect email address (got 'root@....(none)')

The (none) suffix comes from the hostname lookup failing or from the container's hostname not being a domain. Nothing about the repository is broken; the environment simply has no identity.

bash
git config --global user.name "CI Bot" git config --global user.email "ci@example.com" git config --global user.useConfigOnly true

user.useConfigOnly tells Git to stop guessing from the environment at all, which turns a silent wrong author into the same clear error every time.

Key Comparison Table

SourceScopeWins overTypical use
git -c user.email=...one commandeverythingscripts, hooks, CI
.git/configrepositoryglobal and systemwork repository on a shared machine
~/.gitconfigusersystempersonal default
/etc/gitconfigmachinenothingmanaged developer images
EMAIL environment variableprocessauto-detection onlylegacy scripts
OS user and hostnamefallbacknothingthe guess that fails
SituationCorrect placeCommand
new laptopglobalgit config --global user.email ...
one work repolocalgit config user.email ... inside the repo
CI jobenv or -cGIT_AUTHOR_EMAIL or git -c
Docker build step-cgit -c user.email=... commit
pairing session--authorgit commit --author="Name <mail>"
fix an existing commitamendgit commit --amend --reset-author
Wrong identity symptomCauseFix
commit shows root@...no config in containerset -c or env
commit unlinked on GitHubemail not on the accountadd the email or use the noreply address
gpg failed to sign the datasigning key email differsalign user.email with the key
mixed authors in one branchglobal config changed mid-workper-repo config

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Containers, CI and root

CI images usually run as root with no home configuration. Setting the identity in the pipeline is one line, and it keeps the author meaningful in history:

- name: commit run: | git config user.name "release-bot" git config user.email "release-bot@users.noreply.github.com" git add dist git commit -m "chore: build $(date -u +%Y-%m-%dT%H:%M:%SZ)"

Alternatively pass GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL as environment variables; Git uses them ahead of auto-detection. Environment variables are convenient, but they silently override configuration, so a job that sets them keeps overriding a developer's local choice if the job is run through a wrapper script.

bash
env GIT_AUTHOR_NAME="CI Bot" GIT_AUTHOR_EMAIL="ci@example.com" \ GIT_COMMITTER_NAME="CI Bot" GIT_COMMITTER_EMAIL="ci@example.com" \ git commit -m "chore: sync"

2. Two identities on one machine

A developer with a personal GitHub account and a work GitLab account should not edit the global config before every commit. includeIf selects a config file based on the repository path:

ini
# ~/.gitconfig [user] name = Ryu email = ryu@personal.example.com [includeIf "gitdir:~/work/"] path = ~/.gitconfig-work
ini
# ~/.gitconfig-work [user] email = ryu@company.example.com

git config --show-origin --get user.email inside ~/work/api then reports the work file, and inside ~/side-project the personal one. The trailing slash in gitdir: matters; without it the pattern can match sibling directories with the same prefix.

3. Commits already made with the wrong author

The quickest repair is amending the last commit:

bash
git commit --amend --reset-author --no-edit

--reset-author rewrites the author and committer to the current configuration, which is exactly what a container commit needs. For several commits, an interactive rebase with --reset-author on the range, or a filtered rewrite when the branch is already pushed and the team agrees:

bash
git rebase -i HEAD~5 --exec 'git commit --amend --reset-author --no-edit'

Rewriting published history requires a force push, so treat it as a team decision rather than a cleanup habit. A .mailmap file maps old addresses to the right person for git log and git shortlog output without touching commits at all:

Ryu <ryu@example.com> <root@f3c9a1b2c4d5.(none)>

4. Linking commits to a GitHub account

A commit's author email must be one of the verified addresses on the account, or GitHub shows the commit without a profile link. The noreply address works everywhere:

bash
git config user.email "12345678+ryu@users.noreply.github.com"

Changing the email later does not relink old commits; that is what the mailmap or a rewrite is for. For repositories where contributions are verified, keep the email that holds the signing key.

5. Signing keys and the identity

commit.gpgsign with a key whose user id does not match user.email produces a different failure, often gpg failed to sign the data, which hides the real cause:

bash
git config user.signingkey "ABCD1234" gpg --list-secret-keys --keyid-format=long git log --show-signature -1

The simplest fix is to make the configured email match the key's identity, rather than adding a second key.

6. Scripts that must not inherit a developer's identity

Tooling that creates commits on behalf of a service should be explicit, so its history does not depend on whoever ran it:

bash
git -c user.name="changelog-bot" -c user.email="changelog@example.com" \ commit -am "docs: regenerate changelog"

When a script needs several identities or values, keep them in environment variables and check them with the environment variable formatter; when comparing two .gitconfig files across machines, the diff checker shows the lines that differ.

Common Compilation/Runtime Mistakes & Version Gotchas

  • Setting only user.name. The error names the email; both keys are required for a commit.
  • Using --global inside CI. It writes to a home directory that may be discarded, and it hides which job produced the commit.
  • Editing .git/config by hand with the wrong indentation. git config validates the file; manual edits that break it produce a parse error rather than a missing identity.
  • Expecting EMAIL to be enough. It fills the email only; the name still comes from configuration or the OS record.
  • Version notes. user.useConfigOnly has been available since Git 2.8, and includeIf since 2.13, so both work on any supported release. Git 2.40 and later print the auto-detected value in the error, which is the fastest way to see what the fallback produced.
  • Assuming a GUI client fixed it. Desktop clients often set the repository-local identity only; a terminal commit in another clone then fails again.

Official documentation: First-Time Git Setup and the git config reference.

Official references

primary documentation

The Git documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Git guides

More in Git

All Git guides

The guides filed next to this one in Git, in library order.