How to delete git branches with a pattern?

Photo by Yancy Min on Unsplash

This is just a quick tip on how to delete local branches whose names match a certain pattern.

Imagine you are doing a cleanup of your local branches that have already been merged. You want to delete more than one branch, and you have some pattern that you want to use to match branch names.

The solution consists of two commands like this:

$ git branch --list 'pavel/*' | xargs -r git branch -d

This can save a lot of time looking for all such branch names.

--

--