Git: List and remove all remote branches which have already been merged

Sometimes you need to do some spring cleaning on your remote branches (such as GitHub).

To hell with doing it manually!

Fortunately it's an easy fix for us lazy sods.

List all remote branches which have been merged into master

git branch -r --merged | grep origin | grep -v '>' | grep -v master | xargs -L1 | awk '{sub(/origin\//,"");print}'

Remove all remote branches which have been merged into master

git branch -r --merged | grep origin | grep -v '>' | grep -v master | xargs -L1 | awk '{sub(/origin\//,"");print} | xargs git push origin --delete

Digging-Like-a-boss

It just works.

Source

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog