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
  • Keep Your Sass Directories Organized

    If you spend the majority of your time writing a lot of front-end code, specifically CSS or Sass, you understand the importance of organization. While CSS and more specifically Sass, are powerful languages, they can easily become bloated, hard to maintain, and simply put, a hot mess.

    Read More
  • What to Expect As a Developer at Made By Munsters

    Are you thinking of joining Made By Munsters' Development team? Here is a little insight into our team's work habits, how we communicate and what we use to get the job done. Even more interested now? Send us a message so we can setup a time to talk and see if we are a good match.

    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