List all git local branches that start with string List all git local branches that start with string unix unix

List all git local branches that start with string


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.


You just need to tell xargs not to execute its command if it has no input.

You do that with the -r or --no-run-if-empty argument.

git for-each-ref --format="%(refname:short)" refs/heads/abc\* | xargs --no-run-if-empty git branch --list