LoginSignup
4

More than 5 years have passed since last update.

[Git]カレントブランチをブランチ名を指定せずにプッシュする

Last updated at Posted at 2017-04-27

追記

コメントで以下のコマンドで同じことができると教えていただきました!!
こちらのほうが遥かに簡潔ですね

$ git push origin HEAD

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

追記2

同僚に以下の設定をするのが一番楽と教えていただきました

$ git config --global push.default simple
$ cat ~/.gitconfig | grep default                                                                  # Use the Git 1.x.x default to avoid errors on machines with old Git
    # `git config --global push.default simple`. See http://git.io/mMah-w.
    default = simple

Git v2.0 からは simple がデフォルト設定になっているとのことですが、
一応設定しておいたほうが安心できますね。

現在のブランチ名は以下のコマンドで取得できる

$ git rev-parse --abbrev-ref HEAD

カレントブランチにpush

$ git push origin $(git rev-parse --abbrev-ref HEAD)

fish では $() でコマンド展開できないので以下のようにかく

$ git push origin (git rev-parse --abbrev-ref HEAD)

エイリアスに登録

$ balias gpoc 'git push origin (git rev-parse --abbrev-ref HEAD)'

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
4