$ git branch --no-color --merged | grep -v master | grep -v \* | xargs git branch -d
List all local branches.
--merged filter branches that were already merged into a specific branch (master by default) and
--no-color a turn off branch colors, useful for later filtering with grep.
Filter protected branches with
grep -v <pattern>.
xargs to send the output of the first command as arguments to
git branch -d.