List of all git local branches starting with a line
I want to list all local branches (eventually delete, but for the sake of safety ...) that ONLY start with abc. The point is that such works. But if a branch does not start with "abc", it will list ALL branches. what i dont want to do (deleting all my local branches)
git for-each-ref --format="%(refname:short)" refs/heads/abc\* | xargs git branch --list
+3
user3521314
source
to share
1 answer
You just need to tell xargs
not to execute your command if it has no input.
You do it with an argument -r
or --no-run-if-empty
.
git for-each-ref --format="%(refname:short)" refs/heads/abc\* | xargs --no-run-if-empty git branch --list
+3
Etan reisner
source
to share