Python script to delete merged git branches
One of the great things about git is how fast it is. You can create a new branch, or switch to another branch, almost as fast as you can type the command. This tends to lower the impedance of branching. As a result, many individuals and teams will naturally converge on a process where they create many, many branches.
If you’re like me, you may have 30 branches at any given time. This can make viewing all the branches unwieldy. Once I week or so, I would go on a branch deletion spree by manually copying and pasting multiple branch names into a git branch -D
statement.
The basic use case is that you want to delete any branches that are already merged into master. Here is a python script that automated just that.
To print the branches that would be deleted, just execute python delete_merged_branches.py
. To actually delete the branches, execute python delete_merged_branches.py --confirm
.