Skip to content

Trunk-Based Development Instead of a Branch Graveyard

Short integration cycles with feature flags beat long-lived branches: daily integration without merge hell and a release that becomes a decision instead of a deploy event.

≈ 10 min readSoftwareDelivery

If you postpone integration, you haven’t avoided the conflict – you’ve just let it accrue interest. A branch called feature/redesign that runs alongside master for six weeks picks up a few changes every day that nobody checks against the current state anymore. The merge at the end is then no longer a work step but an excavation – and nobody can say beforehand how long it will take. Repositories in which half a dozen such branches slowly age away are what I call the branch graveyard in reviews.

The way out isn’t the next branching model but less distance: integrate into a shared state daily, keep it shippable at all times and separate switching on a feature from rolling out the code. That sounds like Git cosmetics, but it affects lead times and fixing bugs. Deploy and release are two different things – everything else hinges on this separation. It isn’t free, though: every flag creates additional states, testing effort and a cleanup task.

The actual idea: keep the integration distance small#

Let’s start with the core idea, not the tool. Trunk-Based Development – as Paul Hammant describes it on trunkbaseddevelopment.com – essentially means: all developers integrate their work into a single shared branch at least once a day. Let’s call it main or trunk. This branch stays releasable at all times. Branches, if they exist at all, are short-lived – well under a day.

The key concept behind this is integration distance. Every day a branch lives away from the trunk increases the distance between what I’m working on and what the rest of the team sees. This distance isn’t linear. It grows disproportionately, because changes pile up on both sides and can conflict with each other. A merge after six weeks isn’t six times as expensive as one after a week but many times that – and above all, it’s unpredictable.

Martin Fowler gets to the heart of this with his notion of Continuous Integration, and more literally than many read it. “Continuous Integration” really means integrating continuously. A long-lived feature branch is by definition the opposite: deferred integration. You can’t practice Continuous Integration and sit on your own branches for days at the same time. One rules out the other. In his Patterns for Managing Source Code Branches, Fowler provides the matching taxonomy: integration frequency, the notion of the “healthy branch,” the mainline. Once you have internalized this vocabulary, you spot the branch graveyard immediately.

What the data says – carefully phrased#

I’m skeptical of methodology promises that rest only on gut feeling. That’s why I value the work of Nicole Forsgren, Jez Humble and Gene Kim in Accelerate and the State of DevOps Reports. There, Trunk-Based Development isn’t treated as an opinion but as a statistically identified capability.

I phrase this deliberately carefully, because the temptation to exaggerate here is great. The data shows: higher software delivery performance correlates with few active branches in the repository – on the order of three or fewer – and with merges into the trunk at least once a day. Trunk-Based Development is one of the practices that statistically predict Continuous Delivery. Not “guaranteed to cause” but predicts and correlates. This difference is too important to blur when quoting. But the direction is clear, and it matches what I observe in teams: if you keep the integration distance small, you deliver faster, break things less often and with less drama.

The flawed thinking: deploy isn’t release#

Now comes the part where many discussions tip over. “If everyone merges to the trunk all the time – how is anything half-finished ever supposed to stay out of production?” This question is fair, and its answer is the real lever of this whole approach.

Deploy and release are two different events. Deploy means: the code is on the production environment. Release means: the behavior is active for users. Feature toggles – described by Fowler in the bliki and systematized in detail by Pete Hodgson in Feature Toggles (aka Feature Flags) – decouple exactly these two things. The code is rolled out, but the feature is switched off. Activation becomes a configuration and business decision, not a technical deploy event with a night shift and a rollback plan.

flowchart LR
    subgraph friedhof["Branch graveyard"]
        direction TB
        M0["main"] --> M1["main"]
        M0 --> B1["feature branch<br/>day 1"]
        B1 --> B2["... day 20 ..."]
        B2 --> B3["diverges far"]
        M1 --> MG(("big<br/>merge conflict"))
        B3 --> MG
    end
    subgraph tbd["Trunk-Based"]
        direction TB
        T0["trunk"] --> T1["+ commit"]
        T1 --> T2["+ commit"]
        T2 --> T3["+ commit"]
        T3 --> T4["trunk stays green"]
        T4 -. "toggle on<br/>= release" .-> R(("Release<br/>as a switch"))
    end

The diagram shows the core: on the left, a branch diverges over twenty days and ends in a painful merge. On the right, a continuous trunk flows with many small commits, and activation happens on a separate axis – decoupled in time from the merge and the deploy. Release becomes a switch.

Hodgson distinguishes four categories of toggles, and this distinction is valuable in practice because each has a different lifecycle. Release toggles hide unfinished work and are meant to be short-lived. Ops toggles control operational behavior, for example to switch off an expensive function under load. Experiment toggles drive A/B tests and fit well with the Build-Measure-Learn idea from Eric Ries’ Lean Startup. Permission toggles unlock behavior for specific user groups. If you don’t keep these four apart, you end up treating every flag the same – and that comes back to bite you.

How unfinished work lives safely on the trunk#

A release toggle in its simplest form looks like this. What matters is that the flag isn’t scattered as a loose if in the domain code but sits behind a clean abstraction:

// The domain code does not know about flag plumbing.
// It asks a small, well-named abstraction.
if (features.isEnabled("new-checkout-flow")) {
    return newCheckoutService.process(cart);
}
return legacyCheckoutService.process(cart);

The configuration side decides whether a deploy is also a release. A disabled flag means: the code is there, but nobody sees it. That’s deploy without release:

features:
  new-checkout-flow:
    enabled: false        # deploy != release
    strategy: canary      # gradual rollout instead of big-bang
    percentage: 5         # start with 5% of traffic

For large rebuilds, though, a single if isn’t enough. When I replace a central module, the Branch by Abstraction pattern helps – described by Fowler and attributed to Paul Hammant. The idea: I introduce a shared interface under which the old and the new implementation live in the trunk at the same time. Switching happens through a factory or a toggle. Instead of a weeks-long branch, I integrate a large refactoring in small steps that are integrated daily:

public interface PaymentGateway {
    PaymentResult charge(Order order);
}

// Both live in the trunk at the same time.
final class LegacyPaymentGateway implements PaymentGateway { /* ... */ }
final class NewPaymentGateway    implements PaymentGateway { /* ... */ }

// A factory selects the implementation behind a toggle.
PaymentGateway gateway = features.isEnabled("new-payment-gateway")
        ? new NewPaymentGateway()
        : new LegacyPaymentGateway();

In addition, there are dark launching and the keystone interface: you build a large feature piece by piece but put the visible element – the keystone – in place only at the very end. Until then, the new code may already be running along, collecting data or being tested against production load, without any user noticing. Canary releases and blue-green deployments play into this too: rolling out and activating become gradual, controllable processes instead of a big bang.

The contrast: GitFlow and the reflex toward the long branch#

I want to be fair. GitFlow, which Vincent Driessen introduced in 2010 in “A successful Git branching model,” was a well-thought-out answer to a real problem – for a particular kind of software. In 2020, Driessen himself added a note that his model wasn’t intended for continuously delivered web apps. That’s exactly the point. If you build a product with versioned releases and long support cycles, you can live well with a branching model like GitFlow. If you run a continuously delivered application, you get the branch graveyard delivered right to your door.

As a lighter alternative, GitHub Flow has existed since 2011: a short-lived branch, a pull request, a quick merge back into the mainline. That’s already much closer to Trunk-Based Development. The real difference isn’t in the tooling but in the question of how long a team is willing to postpone integration. The longer the answer, the more expensive the bill.

Honest about the pitfalls#

The approach doesn’t solve everything, and it brings its own problems. There are three edges where teams reliably cut themselves.

First: toggle debt, the toggle graveyard. The irony is bitter. You introduce feature flags to avoid the branch graveyard and in the process produce a new graveyard of flags that were never removed. Every release toggle that stays in the code after the release is technical debt. It doubles paths, confuses readers and rots quietly. Hodgson is clear here: release toggles need an expiration date and must be actively removed. In the teams where this worked, removing the flag was a fixed part of the definition of a finished feature – it was only done once its release toggle had disappeared from the code again.

flowchart LR
    A["create toggle"] --> B["deploy dark"]
    B --> C["gradual release"]
    C --> D["fully on"]
    D --> E["remove toggle"]
    E --> F["trunk stays clean"]

Second: Trunk-Based Development without robust test automation and a CI gate is dangerous. The whole approach stands or falls with the trunk staying green and releasable. If builds and tests are slow or unreliable, you import instability directly into the mainline instead of isolating it in branches. In poorly tested codebases, the long branch is sometimes a rational form of self-protection. The right order is therefore: first fast, reliable tests and a gate, then daily integration. Not the other way around. If you also fear integration risks between services with frequent merges, consumer-driven contract testing – for example with Pact – gives you an effective safety net.

Third: the test matrix explosion. Every flag combinatorially doubles the possible paths through the code. Two flags result in four states, three in eight. Untested flag combinations are a real risk space, not a theoretical one. The discipline against this is unspectacular but effective: few toggles active at the same time, clear ownership for each one, and a deliberate eye on the combinations that can actually occur together.

Why the effort pays off#

When I pull all of this together, I don’t end up with a tool recommendation but with an attitude toward delivery. Small integration distance, a trunk that is releasable at any time and the clean separation of deploy and release together produce something that shows up in business numbers.

Cycles get shorter, because nobody loses days in merge conflicts anymore. Friction in the team drops, because everyone works against the same current state and conflicts are small and frequent instead of big and rare. Quality rises, because a feature is rolled out gradually and reversibly instead of in a single risky leap. And the release loses its terror: it’s no longer a nightly deploy event but a decision that someone makes with a switch – reversible, measurable, calm.

In the end, that’s the appeal of the approach. It replaces process overhead with something simple and elegant. Instead of an elaborate branching model that manages the merge pain, you avoid the pain by never letting it arise. The branch graveyard isn’t a law of nature. It’s a consequence of postponed integration – and that can be abolished.

Further reading#

Revised and translated from German with the help of AI.