I have a team member who inadvertently pushed over 150 of his local branches to our central repo. Thankfully, they all have the same prefix. Using that prefix, is there a gi
Github also has a nice UI and mechanism for quickly deleting branches, that's if you'd rather use a UI
I think my way deleting remote branches is the best.
git branch -r | grep -v master | sed 's/origin\//:/'| xargs git push
Everyone is using awk
, not sure why. I feel like that's more complex. Here is what I use to delete all remote branches on my fork
remote:
$ git branch -r --list 'fork/*' | sed 's/fork\///' | xargs git push --delete fork
Throw in a grep
between the xargs
and sed
if you need to filter the list down to only a subset of remote branches.
I tried to delete all origin/release/r1-1* remote branches, hence following command line worked nicely.
git branch -r | awk -Forigin/ '/\/*r1-1/ {print $2}' | xargs -I {} git push origin :{}
Use the following command to remove all branches with PREFIX
prefix on remote server.
git branch -r | awk -F/ '/\/PREFIX/{print $2}' | xargs -I {} git push origin :{}
You may want to do a dry-run first to see if it is the branches that you want to remove:
git branch -r | awk -F/ '/\/PREFIX/{print $2}'
If you like a simpler approach, for instance delete 3 or 4 branches:
git push origin --delete <branch1> <branch2> <branch3>
Important: Only works on Git v1.7.0 and above.