できない.dev

Git pull で「Need to specify how to reconcile divergent branches」が消えない

Git 2.27 以降、ローカルとリモートが分岐していると pull の統合方法を明示しないと止まる。
pull.rebase を設定するか、その場でオプションを付ける。

公開: 更新:

実行例あり(2026-09-01 に実環境で検証)

要約

fatal: Need to specify how to reconcile divergent branches は、Git 2.27 以降で git pull したときに、ローカルとリモートが分岐していて fast-forward できないのに、統合方法(マージかリベースか)が設定されていないと出る。

不具合ではなく、既定を曖昧にしないための仕様変更。pull.rebase を一度設定すれば以降は出なくなる。

実行例

ローカルとリモートが分岐した状態で git pull を実行すると、hint で 3 つの設定を提示したうえで fatal になり、終了コードは 128 になる。git config pull.rebase false を入れてから同じ git pull を打つと ort 戦略でマージが作られ、git log --oneline にはマージコミットと双方のコミットが並ぶ。

warning: You appear to have cloned an empty repository.
$ git pull
From /tmp/tmp.IOKHLi/origin
   2adba68..b15ac78  master     -> origin/master
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint:   git config pull.rebase false  # merge
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
$ echo $?
128
$ git config pull.rebase false
$ git pull
Merge made by the 'ort' strategy.
 a.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
$ echo $?
0
$ git log --oneline
ce86b46 Merge branch 'master' of /tmp/tmp.IOKHLi/origin
3b92cb8 b2
b15ac78 a2
2adba68 base

— 2026-09-01 時点の出力

検証環境

検証日
実行環境
alpine/git Alpine Linux v3.24
バージョン
  • Git 2.54.0

この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。

よくある原因

  1. 2.27 の挙動変更: 以前は暗黙にマージしていたが、明示設定を促すようになった。
  2. 分岐している: git pull の前にリモートにもローカルにも別々のコミットがある。
  3. 未設定: pull.rebase や pull.ff を設定した記憶がない。

解決策

1. マージで進める(既定に近い挙動)

git config pull.rebase false

分岐時はマージコミットを作って統合する。
チーム開発で無難な既定。

2. リベースで直線化する

git config pull.rebase true

ローカルのコミットをリモートの先頭に載せ直し、履歴を直線に保つ。

3. 早送りだけ許す

git config pull.ff only

fast-forward できるときだけ pull し、分岐していれば失敗させて手動対応にする。

4. その場限りで指定する

git pull --no-rebase   # マージ
git pull --rebase      # リベース
git pull --ff-only     # 早送りのみ

グローバルに固定したくない場合は、コマンドのオプションで都度指定する。
全リポジトリ共通の既定にしたいときは、上の git config に --global を付ける(例: git config --global pull.rebase false)。

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