LoginSignup
1
1

More than 1 year has passed since last update.

git pullをやろうとしたら警告文が表示された件

Posted at

Udemyでgitの講座を受講中にgit pullを実行したら警告文が表示されたのでその対処をしました。

講座の内容としては、

自分がmasterブランチで作業し変更をリモートリポジトリにpushしたあと、他のチーム開発メンバーがmasterブランチに変更を加えたので、ローカルにpullで内容を取り込もうというもの。

講座は順調に進んでいるのに自分だけ意味のわからない警告文が表示されました_:(´ཀ`」 ∠):


ちなみに実行環境は

mac os bigsur
デフォルトであるターミナル。

以下のような警告文。

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.

日本語に翻訳すると、

警告:分岐したブランチを調整する方法を指定せずにpullすることはお勧めしません。
次のpullの前に、次のコマンドのいずれかを実行することで、このメッセージを抑制できます。

   git config pull.rebase false # マージ(デフォルトの戦略)
   git config pull.rebase true  # リベース
   git config pull.ff only      # fast-forwardのみ

「git config」を「git config --global」に置き換えることで、全リポジトリにデフォルトを設定できます。
コマンドラインで--rebase、-no-rebase、または--ff-onlyを渡すことで、起動毎にデフォルト設定を上書きできます。

調べてみると、

gitのバージョンが 2.27.0以降 から出るようにあったらしい。

私のgitのバージョン↓

$ git version
	git version 2.36.0

おそらくだけど、

git pullはリモートブランチからローカルブランチに変更内容を統合するので、本来ならマージしない方がいいブランチを統合したために発生するバグやミスを防ぐために警告文が表示されるようになったのではないかと推測。

それぞれのコマンドの特徴としては

こちらの記事が参考になりました。

https://choihack.com/post/プログラミング/git-pullしたときのエラー/

講座内容にそってfast forwardで実行

警告文には

次のpullの前に、次のコマンドのいずれかを実行することで、このメッセージを抑制できます。

と書いてあるのでgit pullを実行する前にデフォルトの挙動で行いたいなら警告文に表示されたコマンドを実行する必要があるそうです。

$ git config pull. rebase false

#上のコマンドを実行した後にgit pullを実行
$ git pull origin master

以上で警告文は表示されず、リモートブランチからローカルブランチにマージすることに成功しました。

git config は設定に関するコマンドなので、git config pull.でpullに対して条件を設定することができるようです。

私も初学者なので、

初学者の助けに慣れたら幸いです。

1
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
1
1