I want to list all local branches (eventually delete but for safety's sake...) that ONLY begin with abc. The thing is that this kind of works. But if no branch starts with "abc" then it lists ALL of the branches. which is what I don't want to end up doing (deleting all my local branches)
git for-each-ref --format="%(refname:short)" refs/heads/abc\* | xargs git branch --list
To list all branches that begin with "abc":
git branch --list "abc*"
So if you want to delete them, then run the following:
git branch --list "abc*" | xargs --no-run-if-empty git branch --delete
You can append the --force
flag to the command above if you want to live dangerously.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With