目次

    Gitシステムを使っているのなら、リモートリポジトリから git pull しようとしたときにこのエラーが発生することは珍しいことではないです。 ほとんどは "fatal: Need to specify how to reconcile divergent branches" という警告が表示されますが、ときには致命的なエラーになることもあります。

    エラー解決法

    cyberithub@ubuntu:~$ git pull origin main From https://cyberithub.com/bitbucket/scm/repo/example-repo *branch dev -> FETCH_HEAD 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.

    以下の3つの解決策を試して、どちらかうまくいくほうでエラーを解決してください! っとその前に git --version コマンドを使用して現在の git のバージョンを確認してください。

    cyberithub@ubuntu:~$ git --version git version 2.35.1

    ① git config pull.rebase false

    ローカルブランチにないリモートの変更があった場合は、それを解決する必要があります。Git のデフォルトの挙動はマージで、ローカルブランチに新しいコミットを作成してその変更を解決します。
    git config pull.rebase false コマンドを使えば、リベースの代わりにデフォルトのマージに切り替えることができます。

    デフォルトの戦略に戻した後、再度 git pull origin (pillしたいブランチの名前) をしてコマンドを実行してブランチからすべての変更を取得してみてください。

    ② git config pull.rebase true

    git pull --rebase を行う場合と同じです。
    git fetch を行った上で、ローカルブランチに対して rebase を実施するので、merge commit が作られずに、コミット履歴が一直線になります。

    ③ git config pull.ff only

    fast-forward 可能な場合のみ、 fast-forward します。
    そうでない場合は、 merge/rebase せず、エラー終了します。

    最後に

    さて、軽くですが今回お話したエラーについて説明させていただきましたがいかがだったでしょうか。数人で作業する際は先祖返りや重複した作業を防ぐ為に、ぜひチーム間で気をつけたい事項ですね。

    読んで頂きありがとうございます。

    PREV
    2022.08.10
    Laravel Pestを利用してテストコードを書いてみよう
    NEXT
    2022.08.12
    最新版Webpack入門 超快適なWebサイト制作の開発体験を【前編】