Created
December 17, 2012 13:55
-
-
Save leoapost/4318441 to your computer and use it in GitHub Desktop.
Delete all remote branches, except master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Replace REMOTE_NAME with your remote name (e.g. origin) | |
git branch -r | grep REMOTE_NAME/ | grep -v 'master$' | grep -v HEAD| cut -d/ -f2 | while read line; do git push REMOTE_NAME :$line; done; |
Might want to try git branch -r | grep origin/ | grep -v 'master$' | grep -v HEAD | cut -d/ -f2 | parallel git push origin --delete
, which is faster. Refer https://www.gnu.org/software/parallel/.
@leoapost This command does not work for branches with /
in its name. To fix this, you need to replace cut -d/ -f2
with cut -d/ -f2-
git branch -r | grep REMOTE_NAME/ | grep -v 'master$' | grep -v HEAD| cut -d/ -f2- | while read line; do git push REMOTE_NAME :$line; done;
Works gr8, thanks 4 sharing.
Sweeeeet, thanks for sharing!
This is great! Thank you for sharing!
Thanks for sharing
Thanks to the OP and others who added additional info. Very helpful!
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect idea. Save a lot of work.
And to be cautious, perhaps do
git branch -r | grep REMOTE_NAME/ | grep -v 'master$' | grep -v HEAD| cut -d/ -f2 | while read line; do echo $line; done;
before delete.