Last Updated: February 25, 2016
·
1.309K
· mnem

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).

3 Responses
Add your response

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 ·