LoginSignup
146
84

More than 5 years have passed since last update.

まだ git push origin するときに current branch 名を入力して消耗しているの?

Last updated at Posted at 2015-12-15

あらすじ

remote の内容を clone して、手元で branch を切って、そのカレントブランチの内容を remote に push したい時、下記のように

git push origin BRANCH_NAME

毎回 BRANCH_NAME を指定する作業をしていると、日に何回も push する時は、とても多くの時間がかかってしまうことがあるかもしれません。

あと、タイトルは単に消耗しているの?って言いたかっただけです。

git push origin HEAD

下記を実行することで、カレントブランチ (git st で確認)の内容を origin に対して push できます。

git push origin HEAD

詳しく

git document によると1

git push origin HEAD
A handy way to push the current branch to the same name on the remote

カレントブランチを同じ名前でリモートに対して push する便利な方法です。
とあります。

同様の stackoverflow 2によると

If you want to push a different branch than the current one the command will not work.

カレントブランチではないブランチを push したいときは HEAD 指定は無効。push したい branch を checkout するか、branch 名を指定する必要があります。

※ 本投稿は http://d.hatena.ne.jp/mabots/20151023/1445584754Coubic Advent Calendar 2015 に向けて、大幅に加筆・再編したものです。

146
84
1

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
146
84