Agile Pantry
Practice

Trunk-Based Development

From DevOps, XP

Everyone integrates small changes into one shared branch at least daily, keeping it always releasable instead of maintaining long-lived feature branches.

Meeting time noneLearning curve Takes months

Helps with

painful releasesbugs and reworkhand-offs and waiting

Needs

Pairs well with

Why it exists

Keep the codebase always integrated and releasable by having everyone commit small changes to one main branch, at least daily.

Why it works

Integration pain grows with branch age: the longer code lives apart, the bigger and riskier the merge. Integrating at least daily keeps conflicts small, gives fast feedback from automated tests, and makes continuous delivery possible. The DORA research programme links trunk-based development to higher software delivery performance.

Before you start

  • A reliable automated build and test suite (continuous integration).
  • Fast test feedback: ideally under 10–15 minutes.
  • A way to hide unfinished work, such as feature flags or branch by abstraction.
  • Code review that keeps pace, through pairing or quick, small reviews.

Don’t use it when

  • There are no automated tests yet. Build continuous integration first.
  • Open-source projects with untrusted contributors, where a fork-and-pull-request model fits better.

Set it up for your context

If your team…Then
Long-lived branches todayShrink branch lifetime in steps: five days, then two, then one.
Reviews are slowPair or work as an ensemble to review as you go, and keep changes small.
Regulated workKeep the audit trail through small reviewed changes or pairing records, and put flags under change control.
Large teamUse short-lived branches of under a day, with a merge queue.

How to introduce it

  1. Measure current branch lifetimes and how painful merges are.
  2. Make the build reliable and fast.
  3. Introduce feature flags for unfinished work.
  4. Agree a maximum branch age and track it.
  5. Fix a broken main branch before doing anything else.
  6. Remove each flag soon after its feature is released.

Variations

Commit straight to trunk
For small, experienced teams with strong tests.
Short-lived feature branches
Branches that last less than a day, merged via quick review.
Branch by abstraction
Replace a large component gradually behind an interface, all on trunk.

Common failure modes

Broken trunk tolerated

You’ll notice The main branch is red for hours and people commit on top.

Fix Stop the line: fixing main comes before any other work.

Flag debt

You’ll notice Dozens of old flags make the code hard to follow.

Fix Track the number of flags and remove each one after release.

Big commits

You’ll notice Daily commits are huge and risky.

Fix Slice work smaller, so each commit is a safe step.

Signs it’s working

  • Median branch age is under a day.
  • Merge conflicts are rare and small.
  • Deployment frequency rises.

What it costs

Setting up
Days to weeks, to make continuous integration reliable and add feature flags.
Ongoing
Discipline rather than time.

How it connects

Sources

  • Trunk Based Development, Paul Hammant and contributors
  • Accelerate, Nicole Forsgren, Jez Humble and Gene Kim (2018)
  • Continuous Delivery, Jez Humble and David Farley (2010)