#!/usr/bin/env bash
git branch --merged "$([[ "${1}" != "-f" ]] && git rev-parse HEAD)" |
  grep -Ev '(^\*|^\s*(main|master|develop)$)' |
  while read -r branch_name; do
    git branch -d "${branch_name}"
  done
