Delobra [delete local branches] is a simple shell script for the opinionated Git user that takes care of doing some seasonal branch removal in your repository.
Solving the Problem
It was born out of distaste with the current Git-flow methodology, especially when dealing with the integration of a high volume of branches with multiple developers and development teams.
Under this workflow, once you are finished with a feature branch you are expected to merge it back into develop and delete the branch. Keeping the branch, however, might prove useful if you later want to revisit your code in the same exact context or work out breaking changes that were introduced in one of many recent merges.
In this case, being able to switch over to the branch to view your work without having to search through commit messages or merge commits might feel like a blessing.
One downside to this, however, is that the number of branches in your repo will skyrocket over time, and having to delete them one by one is a notable pain.
This is where Delobra comes in and helps you safely remove your finished work with ease, letting you keep your branches for an easier workflow until it’s time to clean out the house.
What It Does
Delobra’s job is to compile a list of branches to queue for deletion, check in with you, and (with your approval) delete the branches from your repository.
It is based on this one Git command:
git branch --merged develop
It lets Git know that you want to retrieve a list of local branches that have been merged into the develop branch, which you can change if you want to use a different branch as a “merging filter”.
Building upon this command, Delobra then excludes any other named branches in the list via the use of grep:
| grep -v -e develop -e master
You can remove these exclusions by simply removing any of the command segments beginning with the
-e option and ending with a name, or add your own exclusions by adding the
-e option followed by the name contained by any of your branches.
If you’re using a Git-flow methodology, then Delobra will work for you as you can exclude different branches based on their shared naming structure (i.e. feature, release, hotfix).
Even if you aren’t, you can still delete similarly named groups of branches or customize Delobra to fit your needs.
How To Use It
To run Delobra on your Git repositories:
- Copy over the delobra.sh file to your home directory
- Open a terminal window (or Git Bash if you’re on Windows) in your Git repository directory.
- Run the command
You can find the delobra.sh file on GitHub.
2 thoughts on “Introducing Delobra – Git Branch Deletion for the Opinionated”
I have something similar on my bash history, but I’m a little more aggressive and I pass all the branches after the grep exclude to git branch –delete with xargs 🙂
LikeLiked by 1 person
I was tempted to do so as well but I wanted to pass this on to a few of the people on my team, so by default I wrote it to delete only finished/merged work — otherwise I ran the risk of reading some very angry Skype messages 😥