git czyszczenie starych gałęzi

Chciałbym utworzyć polecenie git, które usunie wszystkie gałęzie, które mają wszystkie zatwierdzenia zawarte w bieżącej gałęzi, np.

$ git branch
  groups
* master

$ git cleanup-branches
deleted groups # all commits are included in master

$ git branch
* master

Jak mógłbym to zrobić?