LoginSignup
4
1

【GitHub】pullできない!Need to specify how to reconcile divergent branchesの内容と解決策

Posted at

はじめに

はじめてpullしようとしたらタイトルの警告文が表示されpullできませんでした。
予期しないことは学びのチャンス!ということで、調べた内容と解決策を書いていこうと思います。

環境

  • macOS:Ventura 13.4
  • Git:2.40.1

表示メッセージ全文

git
➜  myproj git:(main) git pull origin main
From https://github.com/mof-51/myproj
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> origin/main
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.

最終行を見るとNeed to specify how to reconcile divergent branches.と書かれています。
分岐したブランチを調整せずにpullするのは推奨しませんとのこと。
つまりは「pullした時にローカルリポジトリのブランチに対してどうしたいのか決めてからpullして!」ということです。

なんでこんな警告文が出る?

これはGitのバージョンが2.27にアップデートされてから表示されるようになったメッセージで、GitHubの仕様変更によるものです。

"git pull" issues a warning message until the pull.rebase
configuration variable is explicitly given, which some existing
users may find annoying---those who prefer not to rebase need to
set the variable to false to squelch the warning.

引用元:GitHubリリースノート_2.27.0

「pullした時の挙動を決めるまで警告文を出し続けるよ!」と書かれています。

以前のバージョンでのgit pullのデフォルトの挙動はこうでした。

  1. リモートリポジトリからデータをダウンロード
  2. 対象のブランチにマージ

しかし、2.27.0以降はgit pullでダウンロードしたデータをローカルリポジトリに対してどう適用するのかを選択する必要があるんです。

選択肢の違いは?

ここで警告メッセージの一部をもう一度見てみましょう。

git
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

コメントアウトで記載されている通りですが、それぞれの選択肢の挙動は以下になります。

  • git config pull.rebase false:pullしてmergeする
  • git config pull.rebase true:pullしてrebaseする
  • git config pull.ff only:pullしてfast fowordする

解決策

選択肢のいずれかの表示コマンドを打てばpullできるようになります。
なお、コマンドは一度打てばgit configに設定が書き込まれるため、以降のgit pullはすべて同じ挙動になります。

さいごに

間違いなどがありましたらぜひご指摘いただけると幸いです。
最後までお読みいただきありがとうございました!

参考

https://qiita.com/tearoom6/items/0237080aaf2ad46b1963
https://github.com/git/git/blob/master/Documentation/RelNotes/2.27.0.txt

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1