Delete all the merged branches in git
git branch --merged | grep -v '^* ' | xargs git branch -d
This lists all the merged branches (git branch --merged
) filters out the branch beginning with *
which indicates the current branch (grep -v '^* '
) and then uses xargs to send those branch names as arguments to git branch delete (xargs git branch -d
).
Written by David Wagner
Related protips
3 Responses

Awesome, thanks!
over 1 year ago
·

For not deleting master
git branch --merged | grep -v '^* master$' | grep -v '^ master$' | xargs git branch -d
over 1 year ago
·

(Shameless plug) I have a small git commands library, which one is "git purge-branches" that deletes branches merged to master from both local and origin: https://github.com/divoxx/git-fu
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Xargs
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#