gitの使ってないブランチをガッと消すコマンド書いた
バイトで開発するときブランチ切ってプルリクを送る感じで開発してて、ブランチ多いのが気になってたけど、ひとつひとつ消すのもだるいので書いた。
alias rmbr="git branch --merged | grep -v '*' | grep -v 'master' | xargs -I % git branch -d %" alias rmbrall="git branch | grep -v '*' | grep -v 'master' | xargs -I % git branch -D %"
rmbr はマージ済みのブランチを、rmbrall は全てのブランチを消す。 git branchでブランチ名をゲットしたあと、grep -v で使用中のブランチと master ブランチを除外して、git branch -d/D で消す。 git branch -d はマージ済みのブランチを消して、-D はマージされたかどうかにか関わらず消す。
便利。
ちなみに、.gitconfigのaliasはこんなかんじにしている。
[alias] a = add br = branch cl = clone cm = commit co = checkout ga = log --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative gr = log --graph --date=short --decorate=short --pretty=format:'%Cgreen%h %Creset%cd %Cblue%cn %Cred%d %Creset%s' l = log ph = push st = status [color] diff = auto status = auto branch = auto grep = auto