Git push が rejected(non-fast-forward)で蹴られる
リモートブランチに自分のローカルにない新コミットがあると non-fast-forward で push が拒否される。
fetch → rebase / merge してから push し直すのが基本。
公開: 更新:
要約
! [rejected] main -> main (non-fast-forward) のメッセージは
リモートブランチが自分のローカルより進んでいることを意味する。
git fetch → rebase または merge してから push し直すのが基本対応。
なお、括弧内の理由は状況で変わる。
リモートの先行コミットをまだ取得していない(fetch していない)状態では
! [rejected] main -> main (fetch first) と表示され、すでに取得済みでローカル履歴が分岐している場合に
(non-fast-forward) となる。
いずれも fast-forward にならない push が拒否された同じ事象で、対処も同じ。
よくある原因
- 他者の push: 共有ブランチに別の人 or CI がコミットを足した
- force-push 履歴書き換え: 元のコミットが消えてリモート履歴が分岐
- fetch 不足: ローカルが古い HEAD を起点に作業している
- rebase / amend 後: ローカル側の履歴が変わり、リモートと差異が発生
解決策
1. 安全な再同期(共有ブランチで推奨)
git fetch origin
git pull --rebase origin <branch> # コンフリクト発生時は解消して continue
git push origin <branch>2. 自分専用ブランチで履歴を上書きしたい場合
git push --force-with-lease origin <branch>--force-with-lease は リモートが想定通りの状態の時だけ 上書きするため、
他者の新規 push を上書きしてしまう事故を防げる。
3. やってはいけないこと
git push --force origin main # ❌ 共有ブランチでは絶対に NG履歴破壊は復旧が極めて困難。
チームに事故報告と復旧手順が必要になる。
実行例
実際に上記の手順を alpine/git 環境で動かすと、work-b が先行してリモートを更新した状態で work-a が fetch なしに push を試みた際、! [rejected] main -> main (fetch first) が返されて終了コード 1 で停止し、続く git pull --rebase でリベースが完了した後の push は終了コード 0 で成功している。
== versions ==
git version 2.52.0
== run ==
--- セットアップ: bare リモート + 初期コミットを用意 ---
warning: You appear to have cloned an empty repository.
--- 別クローン work-b が先にリモートの main を進める ---
--- work-a は fetch せずに別ファイルで main を進めて push(rejected を想定)---
To /tmp/tmp.HmaIHD/remote.git
! [rejected] main -> main (fetch first)
error: failed to push some refs to '/tmp/tmp.HmaIHD/remote.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
push の終了コード: 1
--- 解決: pull --rebase でリモートの先行コミットを取り込んでから push ---
From /tmp/tmp.HmaIHD/remote
* branch main -> FETCH_HEAD
bda167a..0fa6b62 main -> origin/main
Rebasing (1/1)
Successfully rebased and updated refs/heads/main.
pull --rebase の終了コード: 0
To /tmp/tmp.HmaIHD/remote.git
0fa6b62..5af1d93 main -> main
push の終了コード: 0
--- 解決後の git log --oneline ---
5af1d93 a の更新
0fa6b62 b の更新
bda167a init— 2026-06-14 時点の出力