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
Good solution in case of multiple remotes where we can find few PREFIX combinations.
If you have many (let's say hundreds) branches that were created automatically for example such pattern: build/XXXX. In addition, there is upstream remote and forked origin so that branch -r returns origin/build/XXXX and upstream/build/XXXX as well.
You can use solution with command cut -f2- -d/ More: https://unix.stackexchange.com/a/354984
Dry run where one can combine safe regex patterns like: 33[1-3][0-9] or [0-9]{4}:
git branch -r | grep -Eo "upstream/build/33[0-9][0-9]" | cut -f2- -d/ | xargs -I {} echo {}
The same with real delete from the upstream:
git branch -r | grep -Eo "upstream/build/33[0-9][0-9]" | cut -f2- -d/ | xargs -I {} git push upstream --delete {}