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.

Introduction & Quick Summary
The first commit in a fresh container or a new machine stops with:
*** 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.
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:
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:
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.comThe 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.
# 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.
git config --global user.name "CI Bot"
git config --global user.email "ci@example.com"
git config --global user.useConfigOnly trueuser.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
| Source | Scope | Wins over | Typical use |
|---|---|---|---|
git -c user.email=... | one command | everything | scripts, hooks, CI |
.git/config | repository | global and system | work repository on a shared machine |
~/.gitconfig | user | system | personal default |
/etc/gitconfig | machine | nothing | managed developer images |
EMAIL environment variable | process | auto-detection only | legacy scripts |
| OS user and hostname | fallback | nothing | the guess that fails |
| Situation | Correct place | Command |
|---|---|---|
| new laptop | global | git config --global user.email ... |
| one work repo | local | git config user.email ... inside the repo |
| CI job | env or -c | GIT_AUTHOR_EMAIL or git -c |
| Docker build step | -c | git -c user.email=... commit |
| pairing session | --author | git commit --author="Name <mail>" |
| fix an existing commit | amend | git commit --amend --reset-author |
| Wrong identity symptom | Cause | Fix |
|---|---|---|
commit shows root@... | no config in container | set -c or env |
| commit unlinked on GitHub | email not on the account | add the email or use the noreply address |
gpg failed to sign the data | signing key email differs | align user.email with the key |
| mixed authors in one branch | global config changed mid-work | per-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.
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:
# ~/.gitconfig
[user]
name = Ryu
email = ryu@personal.example.com
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work# ~/.gitconfig-work
[user]
email = ryu@company.example.comgit 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:
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:
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:
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:
git config user.signingkey "ABCD1234"
gpg --list-secret-keys --keyid-format=long
git log --show-signature -1The 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:
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
--globalinside CI. It writes to a home directory that may be discarded, and it hides which job produced the commit. - Editing
.git/configby hand with the wrong indentation.git configvalidates the file; manual edits that break it produce a parse error rather than a missing identity. - Expecting
EMAILto be enough. It fills the email only; the name still comes from configuration or the OS record. - Version notes.
user.useConfigOnlyhas been available since Git 2.8, andincludeIfsince 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 documentationThe Git documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Git guides
All Git guidesGit: fatal: not a git repository (or any parent): .git
The command ran outside a working tree or the .git metadata is gone. Confirm the root, restore a deleted .git, and repair worktree pointers.
Git: fatal: Need to specify how to reconcile divergent branches
Git 2.34 and later refuse to guess between merge, rebase and fast-forward. Set pull.rebase or pull.ff once, and know what each strategy does to history.
Git: could not read Username, terminal prompts disabled
A headless git has no terminal to ask for credentials. Supply a token through a helper, a header or SSH instead of relying on a prompt.
Git: The current branch has no upstream branch
The branch exists locally with no tracking configured. Set upstream once with push -u, or let push.autoSetupRemote do it on every new branch.
More in Git
All Git guidesThe guides filed next to this one in Git, in library order.