Nguyen Le Phong

Trunk-Based Development: Merge Small, Merge Daily

Trunk-based development keeps branches short and merges small changes daily.

The merge conflict starts in a file that looks harmless. Two branches touched the same function for different reasons. One added a validation rule. The other changed the shape of the response. Both changes made sense. After a week apart, together they make a puzzle nobody wants to solve on the last afternoon of the sprint.

Trunk-based development is, in large part, a way to stop paying for that puzzle. This post covers what it actually asks of a team, how you merge unfinished work without shipping it to users, and the habits around tests, review and broken builds that keep it working. At the end there's an easy way to start and three numbers worth tracking.

What it actually means

trunkbaseddevelopment.com defines it as a branching model where developers collaborate on code in a single branch called trunk (usually main) and resist creating other long-lived development branches. Very small teams can commit straight to trunk. Bigger teams usually use short-lived feature branches so a PR can get reviewed and built first, and the site is strict about what "short" means: the branch should only last a couple of days, one developer (two if pairing) works on it, and it gets merged back into trunk when it's closed out.

The DORA research program puts numbers on the practice. In its trunk-based development capability guide, teams do better when they have three or fewer active branches in the repo, merge branches to trunk at least once a day, and don't have code freezes or separate integration phases.

Three short branches each merge back into one trunk line while their changes are still small.
Short branches, merged while they're small. Integration problems show up on day one, while they're still cheap to fix.

Why short branches pay off

The payoff is faster feedback. When work lands every day, conflicts stay small, integration bugs show up early and the whole team sees the real state of the system. DORA says it plainly: the longer a merge is delayed, the more likely it is to cause merge conflicts and the problems that come with them. A long-lived branch feels safe because it keeps unfinished work away from everyone else. In practice it stores up integration cost and hands you the bill at the worst moment.

It's also what makes continuous integration mean something. If there's one branch that represents the current truth, a green build on it tells you something real. If the truth is scattered across eight branches, CI is mostly testing code that will change again before it meets anything else. (For how CI relates to continuous delivery, see Continuous Integration vs. Continuous Delivery.)

Merging code is different from releasing a feature

The most common worry is "so we push half-built features to users?" No. Trunk-based development depends on techniques that separate integrating code from turning on behavior:

  • Feature flags: the code ships dark and gets switched on for a team, a percentage of users, or everyone.
  • Branch by abstraction: put an abstraction in front of the thing you're replacing, build the new version behind it in small merges, then switch over and delete the old one.
  • Backward-compatible changes: add the new column before you read it, read it before you drop the old one.
  • Dark launches: run the new path in production without showing its result, to see how it behaves under real load.
A rollout timeline moving from zero to ten, fifty and one hundred percent of users.
The code is deployed on day one. The flag decides who sees it, and when.

Flags need looking after, though, or you trade branch mess for flag mess. In his guide to feature toggles, Pete Hodgson says release toggles should generally not stick around much longer than a week or two, and that savvy teams treat toggles as inventory with a carrying cost. Some teams add a removal task to the backlog the moment they add a flag, set an expiry date, or add a "time bomb" test that fails once a flag outlives it. Some cap how many flags can exist at once. The feature flags post goes deeper on rollout and cleanup.

Small PRs and fast tests

Small changes are the foundation. A PR that moves one boundary, adds one testable behavior or does one preparatory refactor is easier to review and safer to merge. You stop asking a single PR to explain a whole feature. Each one explains one safe step, and the overall design lives in a short note or ticket.

Fast tests are the other half. If trunk is the shared truth, people need quick confidence that it still works: unit tests, a few focused integration tests, lint, type checks and a small set of end-to-end tests on the flows that matter most. DORA lists skipping automated tests before commit as a common pitfall, because it's how trunk ends up broken. And when the pipeline is slow or flaky, people stop merging often, branches start living longer, and the whole practice falls apart bit by bit.

Review has to keep up

Here's the part teams underestimate. If a PR waits two days for review, your short-lived branch just became a long-lived one. DORA calls this out: when code review is laborious and takes hours or days, developers avoid working in small batches. The fix isn't to lower the bar. Keep the same standard and shrink the unit of review, then agree as a team to pick up review requests fast. Small PRs also get better reviews, which makes it easier for everyone to say yes. (There's more on that in How to Review Code Kindly.)

A red trunk is everyone's problem

Trunk-based development runs on trust. Everyone has to believe the team will keep trunk green, fix a broken build right away, avoid sneaking risky work in, and speak up when a change affects someone else. A broken main blocks the whole team, whoever pushed the commit, so the grown-up response is the same every time: restore the signal first (revert if that's fastest), then find out why it broke and add the guardrail that would have caught it.

A compact CI loop connecting merge, build, test, signal and fix.
When the loop is short, a red build means "stop and fix" instead of noise everyone has learned to ignore.

Start small, then measure

Most teams can't switch overnight, and they don't need to. A reasonable order: shorten branch lifetime first, then speed up the test suite, then add a feature flag for one kind of change, then see how often work actually reaches trunk. DORA lists four things to measure. One is how long review takes, covered above. The other three are easy to count today, so put them where the whole team can see them:

  • The number of active branches (goal: three or fewer).
  • How often each branch is merged to trunk (goal: at least once a day).
  • Code freezes, how many and how long (goal: none).

The point is to reduce late integration surprises, and these three numbers tell you whether that's happening.

Try this week

  • Count your team's open branches and how old the oldest one is.
  • Pick one feature in progress and split the next step into a PR that can merge today.
  • Put the next unfinished change behind a flag, and give the flag an owner and an expiry date.
  • Agree on how fast review requests get picked up, and write it down.
  • Time your CI pipeline. If it's slower than a coffee break, find the slowest step.

The question underneath all of this is simple: how long can your team afford to be away from the shared truth? Every day a branch lives, it drifts a bit further into its own version of reality. Merge often, and you meet back up while the differences are still small enough to fix.

What did you think?