Automatic Local Removal of merged Git Branches

When working with several repositories and feature branches, it can get tedious to clean-up merged and removed branches by hand. A small snippet can do the job automatically.

The following snippet takes all merged branches, except develop and master. The output is written to a temporary file called “merged-branches “. This file is loaded with vim where can review the list of branches which will be locally removed afterwards.

In case you do not need the additional manual verification step, you can omit the temporary file.

The script throws an error in case there are no branches to delete.