DevOps: To branch or not to branch

Image by Lukasz Lada

One of the discussions that comes up from time to time when working with DevOps is branching strategy.

One of the main features of Git that’s often claimed is that it’s so good at branching and merging. And indeed, it’s pretty good at that. But the bigger question is whether lots of branching is desirable in the first place.

One argument says that if you are using branches (let’s say to build features), that you really aren’t doing Continuous Integration (CI). The downside of being features in separate branches is that at some point, you’ll have to merge the code back in, and there’s probably going to be nothing automated about that. One software house that I’ve been mentoring in has a very large number of active live branches.

Each time a merge to a central trunk (ie: master branch) is attempted, it’s beyond painful, often takes months, and introduces enormous numbers of bugs that need to be fixed. If you then combine that scenario with a lack of decent testing, you have a problem. Merging becomes really, really scary.

Image by Priscilla Du Preez
Image by Priscilla Du Preez

There is nothing agile or continuous about that.

The alternative approach is to always work in the master branch. While you can end up colliding with what other people are doing, at least you deal with that right then and there. You can end either with a frustrating set of collisions so that you’re endlessly working with an unstable base, but at least you know about it straight away.

A bigger issue is that it’s easy to accidentally release unreleased features into the wild, or at least parts of them. Feature flags are often used to try to hide this but that can go wrong too.

So in the end, to branch or not to branch? My take on it is that branches are fine if they are letting you try something out in a scratchpad area, and when they are really short-lived. But long term branches aren’t something that I’m keen to see.

Leave a Reply

Your email address will not be published. Required fields are marked *