できない.dev

Git commit できない(Author identity unknown / who you are)

user.nameuser.email が未設定だと commit が「Author identity unknown」で失敗する。
global もしくはリポジトリ単位で名前とメールを設定すればコミットできる。

公開: 更新:

要約

git commit が次のように止まるのは、コミットの作者として記録する名前とメールアドレスが設定されていないためです。
git は誰がコミットしたかを必ず記録するので、user.nameuser.email の両方が決まるまでコミットを作れません。
global に一度設定すれば、以降すべてのリポジトリで使い回せます。

*** 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.
 
fatal: unable to auto-detect email address (got 'user@host.(none)')

よくある原因

  1. 新しい環境で未設定: OS を入れ替えた、別マシン、新しいユーザーなどで一度も設定していない。
  2. リポジトリ単位で空: global には設定があるのに、このリポジトリのローカル設定が優先されて空になっている。
  3. .gitconfig が無い: CI のコンテナや最小構成の環境でホーム配下の設定ファイルが存在しない。
  4. メール自動検出の失敗: ホスト名から推測したメールが無効で unable to auto-detect email address になる。

解決策

1. global に名前とメールを設定する

最も一般的なのは、マシン全体で使う値を global に設定する方法です。

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

設定後にもう一度 git commit を実行すれば通ります。
GitHub に公開したくない場合は、GitHub が提供する noreply メール(...@users.noreply.github.com)を使うとアドレスを隠せます。

2. リポジトリ単位で別の値を使う

仕事用と個人用でメールを分けたいときは、そのリポジトリ内で --global を付けずに実行します。
ローカル設定は global より優先されます。

cd path/to/repo
git config user.email "work@example.com"

3. 反映を確認する

意図した値になっているかは次のコマンドで確認できます。
global とローカルのどちらが効いているかも分かります。

git config --list --show-origin | grep user
git config user.email

実行例

実際に上記の手順を alpine/git 環境で動かすと、設定前の git commit は終了コード 128 で失敗し、git config --globaluser.nameuser.email を設定した後のコミットは終了コード 0 で成功することを確認できます。

$ git commit -m "init"
Author identity unknown
 
*** 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: no email was given and auto-detection is disabled
commit の終了コード: 128
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
$ git commit -m "init"
[main (root-commit) b3bc41b] init
 1 file changed, 1 insertion(+)
 create mode 100644 f.txt
commit の終了コード: 0
$ git config --list --show-origin | grep user
file:/tmp/tmp.LJNjiM/home/.gitconfig	user.useconfigonly=true
file:/tmp/tmp.LJNjiM/home/.gitconfig	user.name=Your Name
file:/tmp/tmp.LJNjiM/home/.gitconfig	user.email=you@example.com

なお、今回の再現では未設定状態を確実に作るため事前に git config --global user.useConfigOnly true を設定しており、そのため commit の失敗メッセージが冒頭に挙げた fatal: unable to auto-detect email address (got 'user@host.(none)') ではなく fatal: no email was given and auto-detection is disabled になっています(上の --show-origin の出力に user.useconfigonly=true が含まれるのもこの設定によるものです)。

自動検出が有効な通常の環境では冒頭のメッセージが表示されますが、原因(user.name / user.email の未設定)と解決策はどちらの場合も同じです。

$ git log --oneline
b3bc41b init

— 2026-08-05 時点の出力

この記事は役立ちましたか?