LoginSignup
172
164

More than 5 years have passed since last update.

git の push.default 設定を理解する

Last updated at Posted at 2013-08-14

git のコマンド入力をサボったら、以下のようなメッセージが。

$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

大抵は、フルで(refspec までは書かないけど) 入力していたけど、安全に楽できそうな気がしたので、設定値を調べてみた。

push.default の設定値

nothing

サボれないようにするための設定。必ず指定する必要がある。

matching

現行バージョンのデフォルト。ローカルとリモートで同じ名前のブランチがあったら、根こそぎ push する。カレントだけではないので、意図しないものまで push されちゃう。

upstream(旧名 tracking)

カレントブランチに追跡ブランチが設定されている場合に、追跡ブランチに対して push する。

simple

Git 2.0 でデフォルトになる予定のもの。カレントブランチに追跡ブランチが設定されている、かつローカルとリモートのブランチ名が同じである場合に、追跡ブランチに対して push する。

current

カレントブランチと同名のリモートブランチがあれば、そこに push する。


これまで事故は起きなかったけど、今後は追跡ブランチの設定をしようかな〜 と思う次第。追跡ブランチの設定方法は、幾つかあるので、現況に応じて使い分ける。

ローカルブランチ作成のタイミングで設定

$ git checkout -t origin hogehoge
  or
$ git checkout --track origin hogehoge

リモートブランチ作成のタイミングで設定

$ git push -u origin hogehoge
  or
$ git push --set-upstream origin hogehoge

既に存在するブランチに設定する

Git 1.7.x スタイル

$ git branch --set-upstream hogehoge origin/hogehoge

Git 1.8.x スタイル

カレントブランチが hogehoge の場合

$ git branch -u origin/hogehoge
  or
$ git branch --set-upstream-to=origin/hogehoge

ローカルブランチも指定する場合、

$ git branch -u origin/hogehoge hogehoge
  or
$ git branch --set-upstream-to=origin/hogehoge hogehoge

もっと前?

$ git branch -t hogehoge origin/hogehoge
  or
$ git branch --track hogehoge origin/hogehoge

といろいろあるけど、track という言葉は使わず upstream へ向かっているようなので、これから覚えるならそっちなんでしょうね。

172
164
4

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
172
164