Skip to main content

Trunk-Based Development: How High-Velocity Teams Stay Out of Merge Hell

Feature flags, short-lived branches and fast CI: what it takes to integrate into main every day and ship with confidence.

Updated 6 min readMarkdown
Part of seriesGit Branching Strategies: A Practical Guide for Teams

Most branching strategies are about managing the separation between people's work. Trunk-Based Development (TBD) flips that: it asks how you can minimize separation altogether.

The answer is blunt. Everyone integrates into one shared branch, main (the "trunk"), at least once a day. Branches, if they exist at all, live for hours rather than weeks.

This is how Google, Meta, and many other large engineering orgs work, and it's strongly correlated with high performance in the DORA research (deployment frequency, lead time, change failure rate, time to restore). It's not magic. It just removes the biggest source of integration pain: long-lived divergence.

Two flavours

1. Direct-to-trunk (small teams)

Developers commit straight to main, usually in pairs or after local tests pass. It works well for small, high-trust teams with excellent automated testing.

2. Short-lived feature branches (most teams)

Developers branch off main, work for a few hours to a day or two, open a small PR, get a quick review, and merge. This is the realistic option for most organizations.

Compare that to GitFlow's diagram. Almost everything happens on one line.

The rules of the road

  1. Integrate at least daily. If your branch is older than two days, something's wrong.
  2. Keep main always releasable. A broken build is the team's top priority, not one person's problem.
  3. Small, incremental commits. Large changes get split into safe slices.
  4. Hide unfinished work behind feature flags, not branches.
  5. Run fast, trustworthy CI on every commit.
  6. Release from trunk, or from short release branches cut off trunk (more on that below).

The part everyone asks about: "How do I ship half-done features?"

This is where TBD either clicks or falls apart. The tools:

Feature flags

Merge the code, but keep it dark until it's ready.

// simple example
if (flags.isEnabled("new-checkout", user)) {
  return renderNewCheckout();
}
return renderLegacyCheckout();

Roll out gradually: internal users → 1% → 10% → everyone. If something goes wrong, you flip a flag instead of redeploying.

Branch by abstraction

For large refactors (say, swapping out a payment provider), you introduce an abstraction, route calls through it, build the new implementation behind it, and flip over when ready. No long-lived branch required.

Steps in practice:

  1. Add an interface around the old code
  2. Move callers to use the interface
  3. Build the new implementation behind the same interface
  4. Gradually switch traffic via a flag
  5. Delete the old implementation and the flag

Dark launches & keystone interfaces

Ship backend code with no UI that exposes it. The "keystone" (the button, route, or menu item) goes in last, and only then does the feature become visible.

What about releases?

Two common approaches:

Release from trunk. Every green commit on main can go to production. Tag when you ship. This is the continuous deployment model.

Short-lived release branches. If you need a stabilization window or must patch released versions, cut a branch off trunk at release time:

git checkout main
git checkout -b release/1.2
git tag -a v1.2.0 -m "Release 1.2.0"

Critical rule: fixes go to trunk first, then cherry-pick to the release branch, never the other way around:

# fix merged to main as abc1234
git checkout release/1.2
git cherry-pick -x abc1234
git tag -a v1.2.1 -m "Patch 1.2.1"

Release branches get deleted when that version is out of support. They never merge back.

What your pipeline needs to look like

TBD fails without strong CI. A reasonable shape:

Target: PR feedback in under ~10 minutes. If your pipeline takes an hour, people will batch changes to avoid waiting, and that's the exact behaviour you're trying to eliminate.

Some practical tricks for staying fast:

  • Run only affected tests on PRs (monorepo tools like Nx, Bazel, or Turborepo help)
  • Parallelize test suites
  • Cache dependencies aggressively
  • Quarantine flaky tests immediately instead of retrying forever

Pros

  • Minimal merge conflicts. Short-lived changes rarely collide badly.
  • Fast feedback and fast delivery. Smaller changes, quicker reviews, more frequent releases.
  • Lower risk per change. A 50-line change is easier to reason about (and revert) than a 5,000-line one.
  • Simple mental model. One main line, little branching overhead.
  • Encourages good engineering habits: testing, modular design, and feature flags.

Cons

  • Needs mature CI/CD and testing. Without it, you're just pushing bugs faster.
  • Feature flag debt is real. Old flags pile up and make code confusing. Assign owners and expiry dates.
  • Cultural shift. Developers used to "finish it, then merge" often find daily integration uncomfortable.
  • Weak fit for open-source with untrusted contributors, where forks and long-lived PRs are the norm.
  • Not ideal for strictly versioned, multi-release products unless combined with release branches.
  • Higher blast radius if the safety net is weak. A bad commit reaches everyone quickly.

Best practices

  • Merge at least once a day. Make it a team norm, not a suggestion.

  • Pair branch protection with fast checks. Require CI and one reviewer, but keep review turnaround to hours, not days.

  • Treat a broken trunk as an incident. Revert first, investigate after:

    git revert <bad-commit>
    
  • Use pre-commit hooks and local test runs so most issues are caught before CI.

  • Track flag lifecycle. Every flag gets an owner and a removal ticket created at the time you add it.

  • Prefer small PRs. If it takes more than ~30 minutes to review, it's probably too big.

  • Invest in observability. Metrics, logs, and alerts let you spot regressions quickly when changes ship constantly.

  • Practice rollbacks. Reverting should be boring.

  • Use progressive delivery: canary deployments, percentage rollouts, automatic rollback on error spikes.

Getting started without a big-bang change

If you're coming from GitFlow, don't flip everything overnight:

  1. Cap feature branch lifetime (start with 3 days, then reduce)
  2. Introduce feature flags for the next big feature
  3. Speed up CI until PR feedback is reasonably quick
  4. Merge develop and main into one branch
  5. Drop release branches unless you genuinely need them

Wrapping up

Trunk-Based Development is less a branching strategy than a discipline: integrate constantly, keep things shippable, and use flags instead of branches to manage incomplete work. It rewards teams that invest in testing and automation, and it punishes those that don't. If your team's ready, the speed gains are hard to beat.


Enjoyed this one? Buy me a coffee and help me keep writing: buymeacoffee.com/vatul16 ☕

Thanks for reading!

About the author

  • Hi, I'm Atul! I am a software engineer with a strong focus on DevOps, Cloud Infrastructure, and automation. I spend my time building scalable CI/CD pipelines, mastering tools like Docker, Terraform, and AWS, and breaking down complex cloud concepts into accessible, hands-on tutorials. I believe the best way to learn is to build, break, and document the process.

No comments yet. Be the first to comment.

Git Branching Strategies: A Practical Guide for Teams

Part 4 of 4

A five-part, hands-on series on Git branching strategies. We go through GitFlow, GitHub Flow, GitLab Flow and Trunk-Based Development, with diagrams, real commands, pipeline examples, pros, cons and best practices. The final post helps you decide which strategy fits your team, release style and level of automation.

Start from the beginningGitFlow Workflow: The Traditional Branching Model, and When It Still Makes SenseA practical guide to main, develop, release and hotfix branches, with commands, diagrams, and the mistakes that trip teams up.