LoginSignup
10
10

More than 5 years have passed since last update.

zshでGitのカレントブランチ名を簡単に入力するalias

Posted at

Gitを使っていると、pushするときなんかに現在のブランチ名を指定することがある。そのときにいちいち手で入力するのも面倒なので、zshのグローバルエイリアスを使って一文字で入力できるようにした。これを~/.zshrcに書いておけばOK。

function git_current_branch_name()
{
  git branch | grep '^\*' | sed 's/^\* *//'
}
alias -g B='"$(git_current_branch_name)"'

使い方はこんな感じ。コマンドライン中にBと入力すると、それがGitのカレントブランチ名に置き換わる。

% git checkout develop #<= developという名前のブランチに移動する
% git push origin B    #<= git push origin developになる

単純なことだけどけっこう便利。

10
10
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
10
10