TIL - How to delete all branches but one

Sometimes it’s time to start over. This script will delete all git branches but one called develop.

git branch --v | grep "develop" -v | awk '{print $1}' | xargs git branch -D

If you don’t trust me, don’t worry, I don’t trust myself either. Just remove the | xargs git branch -D, and the script will only print the result.

[Permalink]

TIL - How to delete all branches that are not in the remote repo

You tried all the possible combinations of prune, you still have branches you want to kill. Try this:

git branch --v | grep "\[gone\]" | awk '{print $1}' | xargs git branch -D

If you don’t trust me, don’t worry, I don’t trust myself either. Just remove the | xargs git branch -D, and the script will only print the result.

[Permalink]