How might we go about cleaning these unwanted branches up?
One way would be to delete each branch at a time, using
git push
combined with our branch name, prefixed with a colon:
git push origin :<unwanted branch>
This works fine for one or two branches, but what if we want to remove many branches in one go?
git br -r | egrep -v "master|<other branches to keep>" | sed "s/\// :/" | xargs -n 2 git push
This script takes all the remote branches, filters them for branches we want to keep, constructs the 'origin :<remote branch>' command suffixes, and then passes each one to
git push
.
If you're at all nervous, back up your repo locally first!
No comments:
Post a Comment