LoginSignup
1
1

More than 3 years have passed since last update.

git pushするときにブランチ名を入力するのが面倒

Last updated at Posted at 2021-01-04

いままで

ローカル環境のブランチをGithub上の同じ名前のブランチにpushするとき、
いままではこんな感じでブランチ名を指定していました。

例)
 ローカル環境でfeature/sampleブランチにいて、
 Github上の同じ名前のブランチ(feature/sample)にpushするとき

$ git push origin feature/sample

問題点

問題点というほどでも無いのですが、毎回ブランチ名を入力しなければならないのが面倒だなぁと思っていました。
いざgit pushしようとしたとき、ブランチ名なんだっけ?となって

$ git branch

で確認することがよくあります。。。

対策

次のコマンドを使えば、ローカル環境の現在のブランチ名でgit pushすることが出来ます。

$ git push origin HEAD

Github上に同名のブランチが存在していない場合でも問題なくpushできます。
(git pushしたブランチと同名のブランチをGithub上に生成してくれます)

便利!

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