gitでブランチ一覧を付番表示して一瞬で切り替えるエイリアス
ブランチ一覧表示から数字選ぶだけでブランチ切り替えできるようになるエイリアスを紹介します。ブランチ名を都度コピペして消耗してましたが、一気に捗るようになりました。
Mac・Linuxを想定しております。bashの場合は以下を~/.bash_profile
に追記してsource ~/.bash_profile
で更新するだけです。
~/.bash_profileの場合
function b() {
command git branch --sort=-committerdate | cut -c 3- | head -n20 | cat -n
command read -p "Enter Branch Number: " BranchNumber
command git checkout $(git branch --sort=-committerdate | cut -c 3- | head -n20 |awk NR==$BranchNumber)
}
zshの場合は以下を~/.zshrc
に追記してsource ~/.zshrc
で更新です。
~/.zshrcの場合
function b() {
command git branch --sort=-committerdate | cut -c 3- | head -n20 | cat -n
read 'BranchNumber?Enter Branch Number: '
command git checkout $(git branch --sort=-committerdate | cut -c 3- | head -n20 |awk NR==$BranchNumber)
}
コマンドは短くb
の一文字を割り当てています。全てネイティブコマンドで動作してますので、カスタマイズも容易かと思います。全てのエンジニアに良いgitライフを!
Author And Source
この問題について(gitでブランチ一覧を付番表示して一瞬で切り替えるエイリアス), 我々は、より多くの情報をここで見つけました https://qiita.com/umihico/items/18df63dac4877105a307著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .