この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:5
更新日時:2026-06-11 07:07:02
タイトル: エラー一覧
SEOタイトル: Git エラー一覧|push / pull / merge / rebase の頻出エラーと対処入口
| この記事の要点 |
- Git のエラー一覧入口ページ
- カテゴリ: リモート / プッシュ系 / 作業ツリー・インデックス / 参照名・ファイル指定 / ロック・プロセス
- 切り分け順: エラーメッセージ最初の 1 行を読む →
git status 確認 → git log --oneline -20 - 頻出: non-fast-forward / merge conflict / Permission denied / detached HEAD / index.lock
- 子ページから個別のエラーを選択
|
Git エラーの 5 大カテゴリ
| カテゴリ | 典型エラー | 原因の方向性 |
| リモート/プッシュ系 | ! [rejected] non-fast-forward / Permission denied | リモートが進んでいる / 認証問題 |
| 作業ツリー/インデックス | Your local changes would be overwritten / Unmerged paths | 未コミットの変更とぶつかる |
| 参照名・ファイル指定 | pathspec did not match any files / ambiguous argument | typo / ファイル存在しない |
| マージ/リベース | CONFLICT (content): Merge conflict / could not apply | 同じ箇所を別 commit で変更 |
| ロック・プロセス | Unable to create '.git/index.lock' / Another git process | 既存 Git プロセス / 異常終了の残骸 |
エラー出たときの調査フロー
- エラーメッセージの最初の 1 行を読む(
fatal: / error: / hint: の見出しが種類を表す)
git status で作業ツリーの状態を確認
git log --oneline -20 で最近のコミット履歴を確認
git remote -v でリモートの設定を確認
git branch -avv でブランチとリモート追従を確認
- 慌てて
git reset --hard や git push --force は取り返しがつかないので慎重に
頻出エラー Top 10
| エラー | 原因 | 対処 |
| ! [rejected] non-fast-forward | リモートに別 commit がある | git pull --rebase → 解決 → git push |
| Permission denied (publickey) | SSH 鍵が設定されていない | ssh-add ~/.ssh/id_ed25519 / GitHub に公開鍵登録 |
| fatal: refusing to merge unrelated histories | 履歴が無関係なリポジトリ同士をマージ | --allow-unrelated-histories |
| Your local changes would be overwritten by merge | 未コミット変更とマージが衝突 | git stash → git pull → git stash pop |
| CONFLICT (content): Merge conflict in xxx | 同じ箇所を別 commit で変更 | ファイル編集 → git add → git commit |
| fatal: pathspec 'xxx' did not match any files | ファイルパスの typo | 正しいパスに直す |
| fatal: Unable to create '.git/index.lock' | 別 Git プロセスが動いている / 異常終了残骸 | rm -f .git/index.lock |
| detached HEAD state | ブランチでない位置をチェックアウト | git switch -c new-branch で新規ブランチ作成 |
| fatal: not a git repository | カレントディレクトリが Git 管理下にない | git init / 正しいディレクトリに移動 |
| HTTP 403 / 401 push 時 | HTTPS 認証情報が古い / Personal Access Token 失効 | git credential 削除 / PAT 再発行 |
「やらかし」リカバリ集
間違って commit した
# 直前の commit を取り消し(変更は残す)
git reset --soft HEAD~1
# 直前の commit メッセージを書き換え(既に push 済みでも可だが force push 必要)
git commit --amend
# 既に push 済みなら revert(新規 commit で打ち消す)
git revert HEAD
git push
間違ったブランチで作業した
# 現在の変更を別ブランチに移す
git stash
git checkout 正しいブランチ
git stash pop
# commit 済みなら cherry-pick
git checkout 正しいブランチ
git cherry-pick <間違ったブランチの commit ハッシュ>
# 間違ったブランチから commit を取り消し
git checkout 間違ったブランチ
git reset --hard HEAD~1
大事なファイルを消した / 上書きした
# 直前の commit 状態に戻す
git checkout HEAD -- path/to/file
# 数 commit 前の状態を取得
git checkout HEAD~3 -- path/to/file
# reflog で「失われた」commit を探す
git reflog
# 該当 commit を確認
git show
# その状態に戻す
git reset --hard
conflict が出たけど解決方法がわからない
# 衝突しているファイル一覧
git status
# 衝突箇所には以下が入っている
# <<<<<<< HEAD
# 自分の変更
# =======
# 相手の変更
# >>>>>>> branch_name
# 手動で編集して <<<<< >>>>>>> を消す
# またはツールを使う
git mergetool
# 解決したら
git add <ファイル>
git commit
# rebase 中なら
git rebase --continue
# 全部取り消したい
git merge --abort
git rebase --abort
push 拒否されたとき
# non-fast-forward の典型
git pull --rebase # リモートの変更を取り込む(rebase 方式)
git pull # マージ方式
# 自分の変更を確実に残したい場合
git pull --rebase
# conflict が出たら個別解決 → git rebase --continue
# ★ NG: 安易に強制 push しない(チームメンバーの commit を消す可能性)
# git push --force ← 危険
# ★ 個人ブランチで完結する場合のみ許容
git push --force-with-lease # 他人の変更があれば拒否(より安全)
子ページ(個別エラー詳細)
- ! [rejected] non-fast-forward の対処
- fatal: refusing to merge unrelated histories の対処
- Permission denied (publickey) の対処
- fatal: Unable to create '.git/index.lock' の対処
- CONFLICT (content): Merge conflict の解決手順
- detached HEAD 状態からの復帰
- 各種 git reset / revert / restore の使い分け
各エラーの詳細解説は子ページを参照してください。