🚨 Gitエラー一覧と対処法

よくあるエラーメッセージと原因・解決策をすぐ確認できるリファレンス

🚫 push時のエラー

エラーメッセージ 原因 対処法
non-fast-forward リモートに新しい履歴がある git pull --rebase で取り込み後、再push
no upstream branch 追跡ブランチが未設定 git push -u origin ブランチ名
remote rejected 保護されたブランチへのpushなど GitHubの設定を確認 or 別ブランチでPR

🔄 pull / merge / rebase時のエラー

エラーメッセージ 原因 対処法
Merge conflict 同一ファイルの同一行が競合 手動で修正 → git addgit commit
Cannot rebase: You have unstaged changes. 未コミットの変更がある 一時保存(git stash)またはコミット
fatal: refusing to merge unrelated histories 履歴に共通点がない(初回pullなど) git pull origin main --allow-unrelated-histories

🔐 認証エラー

エラーメッセージ 原因 対処法
Authentication failed GitHubのパスワード認証廃止 トークンまたはSSHを使う
Permission denied (publickey) SSH鍵が設定されていない SSH鍵を作成しGitHubに登録
Support for password authentication was removed HTTPS認証がトークン必須に 個人アクセストークンを発行・設定

🧩 その他のエラー

エラーメッセージ 原因 対処法
fatal: not a git repository git init していない or ディレクトリ間違い 正しいディレクトリで再確認 or git init
error: Your local changes to the following files would be overwritten... 上書きの恐れがある未保存の変更 コミット or ステージするか git stash
fatal: bad revision 'HEAD' まだコミットが存在しない状態 まずは最初の git commit を実行

記事の閲覧数