LoginSignup
150
83

More than 3 years have passed since last update.

git push origin HEADを知らない人は時間を無駄にしています!

Posted at

はじめに

Gitでカレントブランチ(現在いるブランチ)をリモートの同名ブランチにプッシュする時、今まで次のコマンドを入力してきました。

$ git push origin 現在のカレントブランチ名

ブランチ名が長い時は、直接入力が面倒くさいし、間違えないようにgit branchでブランチ名を確認して、それをコピーして貼り付けるとかやっていたのですが、これは時間の無駄だったことに気づいたので記しておきます。

解決法

このコマンドで全て解決!

git push origin HEAD

Gitのコマンドを検索していると、よくHEADというワードは目にしていたのですが、ややこしい処理になるのではないかと思い避けていました。
HEADは、現在のブランチの先頭、つまりコミットの一番新しいものを指しており、 gitはそこからブランチ名を取得できるので、カレントブランチ名を入力することと同じになります。

参考

公式ドキュメント.
git push origin HEAD
A handy way to push the current branch to the same name on the remote.

150
83
2

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
150
83