Last Updated: February 25, 2016
·
969
· dstrelau

Remove merged branches from a git remote

Bunches of branches cluttering up Github? Here's an easy one-liner to delete branches that are already merged to master:

git branch -r --merged origin/master | grep origin | grep -v master | cut -f2- -d/ | xargs -I% git push origin :%

Bonus! Deleting merged local branches is much the same:

git branch --merged master | grep -v master | xargs -n1 git branch -d

3 Responses
Add your response

delete branch on remote

git push origin --delete <branch name>

I believe this does the same thing?

over 1 year ago ·

@arnonate Ah, yes. I believe the --delete syntax sugar was added in 1.7.0.

over 1 year ago ·

; ) That always annoyed me that I would delete a branch locally, then push to master and they would still be there on the repo... seems like there shouldn't have to be an extra step for that

over 1 year ago ·