LoginSignup
5
3

More than 1 year has passed since last update.

git pullするとhintがたくさん出てくる

Posted at

備忘録の記事です。
ローカルでgit pullした時に、hintとかわらわら出てきました。

やりたいこと

この警告?を非表示にしたい

% git pull origin main
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
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.
From https://github.com/tomoya007/movie-review
 * branch            main       -> FETCH_HEAD
Already up to date.

解決法

メッセージにあるように、以下の 3 つの設定のうち、いずれかを実施すれば、 warning は出なくなります。

git config pull.rebase false
git config pull.rebase true
git config pull.ff only

一旦git config pull.rebase falseしてみる

% git config pull.rebase false
chiharatomoya@rooter movie-reivew(オリジナル版) % git pull origin main
From https://github.com/tomoya007/movie-review
 * branch            main       -> FETCH_HEAD
Already up to date.

とりあえずwarningは出なくなった。

特に、今までの動作に不満がないという人は git config --global pull.rebase false をやっておけば、今までの挙動の通り、 warning だけ出なくなります。

git pull 操作の選択肢

先程の warning に対処するための 3 つの選択肢を考えたいのですが、その前に、 git pull--rebase option について確認します。
何も指定しない場合は、 --rebase false と同じで、これがデフォルトの動作です。 --rebase を指定した場合は --rebase true と同じです。

3 つの選択肢を選んだ場合の挙動

ここまでくれば、 git pull にオプションを付けずに実行したときの動作について、 Git が以下のいずれかを要求していることが分かります。

git config pull.rebase false

デフォルトの挙動です。git pull--rebase option を付けずに実行するのと同じです。
標準動作では rebase せずに fast-forward 可能な場合は fast-forward を行い、そうでない場合は、 merge commit を生成しようとします。

git config pull.rebase true

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

git config pull.ff only

--ff-only option を付けた時と同様、 fast-forward 可能な場合のみ、 fast-forward します。
そうでない場合は、 merge/rebase せず、エラー終了します。

参考:

5
3
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
5
3