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.
Helps with
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
How to introduce it
- Measure current branch lifetimes and how painful merges are.
- Make the build reliable and fast.
- Introduce feature flags for unfinished work.
- Agree a maximum branch age and track it.
- Fix a broken main branch before doing anything else.
- 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
- Continuous Integration Trunk-based development only works with fast, reliable automated builds.
- Continuous Delivery An always-releasable trunk is what makes continuous delivery possible.
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)