vbwcow
Last Updated: February 25, 2016
·
846
· akalyaev
D83b63db79b42978fe35e120550ca180

Remove remote braches that are merged into master

git branch -r --merged master | grep -v 'master$' | sed -e 's/origin\///' | tee | xargs -I branch -p git push origin :branch

Finds branches that have been merged into master, excludes master, replaces 'origin/' prefix, then deletes them all.

Thanks to -p option, console will always ask you for confirmation, so you do not delete branch by accident. Although it is still dangerous, so use this command with caution.

Based on @catchamonkey protip https://coderwall.com/p/oik3ta

Say Thanks
Respond

2 Responses
Add your response

5319
298941b7505eec5e45bea403f71faefe

It is bad practice when you have, for example, master and production branches, If you put your fixes to production branch and then merge it into master, then your script will delete production branch

over 1 year ago ·
5320
D83b63db79b42978fe35e120550ca180

@kelion Thanks, I didn't think about it. I've added -p flag to xargs command for confirmation.

over 1 year ago ·