Managing git branches when branching off multiple feature branches can be a pain. What branches have been merged and can any be deleted?

Within my first few months at Made By Munsters I came to realize that I needed a better workflow for managing my branches.

Let's break down the current workflow. First, at the beginning of a sprint we create a sprint_deploy branch with the date that it was created. This branch is based off the master, because master has the latest code base. From this point, we branch off of sprint_deploy into several feature branches.

Each feature branch is named according to the user story it is addressing, as well as, time stamped with a creation date. For instance feature_addAdminLogin_7_21_16 will contain code that is primarily used to add the admin login functionality.

From here a PR will be made for this branch. If fixes are needed, then the PR reviewer will branch off the feature branch to create the fixes, otherwise, the feature branch developer will fix any changes that need to be made within this branch.

The reason for the seperation is that another developer modifying code needs to be reviewed just as if it was the original PR. At Made By Munsters we pride ourselves on making sure the work is done correctly.

As stated above, we can see that at any point we may have 5 to 10 branches open on our local environments. Manually managing these branches and checking if the code has been merged can be a pain.

For this I have found a simple command that has saved me a ton of time.

# ~./bashrc or ~./zshrc
# removes all branches that have been merged into currently checked out branch
# excluding master branch

alias remove_merged='git branch --merged | grep -v "\*" | grep -v master | xargs -n 1 git branch -d'

The above code allows me to easily checkout the sprint_deploy branch and run remove_merged within my terminal. Without having to think about it, this will remove all branches that have been merged into the sprint branch except for the master branch.

Inspiration for this came from Git Clean.

More posts
  • A Year in Review

    2016 was a big year for your friendly neighborhood Munsters. Our team, our client base, and our project count grew substantially. We built and launched our own product, and

    Read More
  • Craft The Right User Experience Process For Your Team

    Crafting a great process takes time. It takes trial and error. More often then not you have to fail as an organization, as a team and as individuals before you can shape the right process.

    Read More
  • Simulating Poor Network Conditions with Toxiproxy

    There are a number of forces driving the need to increase resiliency in the face of poor network conditions. Web pages are increasingly being replaced by long-running (single-page) web applications, where the web app might be able to continue to work through temporary network disruption or even work fully offline.

    Read More