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
Written by Anton Kalyaev
Related protips
2 Responses
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
·
@kelion Thanks, I didn't think about it. I've added -p flag to xargs command for confirmation.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Branch
Authors
niklongstone
41.97K
muzzlefork
11.98K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#