Trunk-Based Development

Layers of Management ThoughtLayer 6: Improvement PhilosophiesPhilosophyAlso known as Trunk-based development, TBD

A branching practice used since the mid-1990s, set out as a reference by Paul Hammant on trunkbaseddevelopment.com from 2017, and linked to stronger delivery performance in the DevOps Research and Assessment (DORA) analysis of its 2016 and 2017 survey data.

Holds that developers should merge small changes into one shared line of code several times a day and avoid long-lived branches, so that the code stays releasable and integration never becomes a separate project.

Eight pieces of work, sorted by how to keep them on the trunk

Trunk-based development keeps every piece of work on the trunk, finished or not. Select a piece of work, then the box that says how to merge it: finished in a day goes straight in, unfinished work goes in switched off, and a long replacement goes in behind an abstraction. Show the sort to compare yours. Illustrative.

Items (select one, then a box)
  • Not placedPlacedMerge to trunk todayMerge behind a flagBranch by abstraction
  • Not placedPlacedMerge to trunk todayMerge behind a flagBranch by abstraction
  • Not placedPlacedMerge to trunk todayMerge behind a flagBranch by abstraction
  • Not placedPlacedMerge to trunk todayMerge behind a flagBranch by abstraction
  • Not placedPlacedMerge to trunk todayMerge behind a flagBranch by abstraction
  • Not placedPlacedMerge to trunk todayMerge behind a flagBranch by abstraction
  • Not placedPlacedMerge to trunk todayMerge behind a flagBranch by abstraction
  • Not placedPlacedMerge to trunk todayMerge behind a flagBranch by abstraction

Replaces code that others use

YesNo
Branch by abstraction
Merge to trunk today
Merge behind a flag
NoYes

Finished within a day

Fix a typo in a message.Not placed yet.Fix a typo in a message.Merge to trunk today: Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.A single small change with nothing to hide. It goes in today.Fix a typo in a message.Merge behind a flag: New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.Fix a typo in a message.Branch by abstraction: A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.Rename a config setting.Not placed yet.Rename a config setting.Merge to trunk today: Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.Done in an hour and reviewed in minutes, so a long branch would cost more than the change.Rename a config setting.Merge behind a flag: New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.Rename a config setting.Branch by abstraction: A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.Add a field to a reply.Not placed yet.Add a field to a reply.Merge to trunk today: Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.It changes something in use, but only a little. A short-lived branch carries it through review in a day.Add a field to a reply.Merge behind a flag: New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.Add a field to a reply.Branch by abstraction: A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.New checkout page.Not placed yet.New checkout page.Merge to trunk today: Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.New checkout page.Merge behind a flag: New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.It takes weeks and no customer sees it yet. Merged daily and switched off, it never drifts from the trunk.New checkout page.Branch by abstraction: A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.New reporting export.Not placed yet.New reporting export.Merge to trunk today: Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.New reporting export.Merge behind a flag: New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.Nothing depends on it, so a flag is enough. It stays dark until it is ready.New reporting export.Branch by abstraction: A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.Redesigned onboarding flow.Not placed yet.Redesigned onboarding flow.Merge to trunk today: Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.Redesigned onboarding flow.Merge behind a flag: New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.Built over a month in small merges and turned on for a beta group first.Redesigned onboarding flow.Branch by abstraction: A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.Swap the payment provider.Not placed yet.Swap the payment provider.Merge to trunk today: Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.Swap the payment provider.Merge behind a flag: New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.Swap the payment provider.Branch by abstraction: A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.Many parts of the code depend on it. An interface lets old and new run side by side until the switch.Replace the search library.Not placed yet.Replace the search library.Merge to trunk today: Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.Replace the search library.Merge behind a flag: New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.Replace the search library.Branch by abstraction: A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.A long change to something in daily use, which has to stay releasable throughout.

Your sort matched 0 of 8.Your sort matched 1 of 8.Your sort matched 2 of 8.Your sort matched 3 of 8.Your sort matched 4 of 8.Your sort matched 5 of 8.Your sort matched 6 of 8.Your sort matched 7 of 8.Your sort matched 8 of 8.

Merge to trunk today
Small enough to finish and review in a day. Merge it through a short-lived branch or straight in, and let the build check it.
Merge behind a flag
New work that takes longer than a day and that no one uses yet. Merge it daily, switched off in production, and turn the flag on when it is ready.
Branch by abstraction
A long replacement of code others depend on. Put an interface around the old code, build the new version beside it, switch over with a small commit, and remove the old.

The sort

  • Fix a typo in a message: Merge to trunk today. A single small change with nothing to hide. It goes in today.
  • Rename a config setting: Merge to trunk today. Done in an hour and reviewed in minutes, so a long branch would cost more than the change.
  • Add a field to a reply: Merge to trunk today. It changes something in use, but only a little. A short-lived branch carries it through review in a day.
  • New checkout page: Merge behind a flag. It takes weeks and no customer sees it yet. Merged daily and switched off, it never drifts from the trunk.
  • New reporting export: Merge behind a flag. Nothing depends on it, so a flag is enough. It stays dark until it is ready.
  • Redesigned onboarding flow: Merge behind a flag. Built over a month in small merges and turned on for a beta group first.
  • Swap the payment provider: Branch by abstraction. Many parts of the code depend on it. An interface lets old and new run side by side until the switch.
  • Replace the search library: Branch by abstraction. A long change to something in daily use, which has to stay releasable throughout.

An example

A software company with thirty engineers in six teams had a routine: each team worked on its own branch for two or three weeks, then merged during an integration week in which nothing could ship. The merges were painful, the code freeze before each release stretched, and a defect found in the freeze could not be traced to any one change.

The head of engineering sets a rule that no branch lives longer than a day and every team merges to the shared trunk daily, behind an automated build that must stay green. Work that cannot finish in a day goes in switched off. A switch hides the new checkout page, and the replacement of the payment provider is built behind an interface while the old one keeps running. The first month is rough, with broken builds and arguments about review. After three months integration week is gone, the trunk can be released on any morning, and a defect points to a change from the previous day.

The core idea

Trunk-based development keeps a whole team's work on one shared line of code, the trunk, and treats any branch that lives longer than a day or two as a cost. Changes arrive in small batches, merged at least daily, and the build server checks each one. The model needs techniques that let unfinished work live in the trunk without harming it. Feature flags keep new capability switched off in production until it is ready. Branch by abstraction lets a team replace a component that many others depend on: it puts an abstraction around the old code, builds a second implementation beside it, switches over with a small commit, and then removes the old one. Short-lived branches may carry a change through code review and checks. Releases come from the trunk or from release branches cut from it just in time.

The idea beyond the techniques is that integration is cheapest when it is continuous. A large merge combines weeks of different work at once, so the cost of discovering a conflict grows with the time since the last merge.

The thinking behind it

Paul Hammant Paul Hammant maintains the reference site trunkbaseddevelopment.com, whose copyright starts in 2017, and wrote Trunk Based Development and Branch by Abstraction (2020). The site is clear that the model is old: a less familiar choice since the mid-1990s, considered by some teams in the 1980s, and run at scale by very large engineering organizations such as Google and Facebook. Hammant's contribution is documentation. He gave the practice its techniques and their conditions, including where branch by abstraction does not suit, such as products whose customers choose when to upgrade.

Where it sits in the layers

Trunk-Based Development sits in Layer 6, the improvement philosophies, because it prescribes a way of working that makes delivery faster and safer, and gives a reason: small batches expose problems sooner. It draws on the logic of Feedback Loops in Layer 1, since a short loop between a change and its test is worth more than a long one. Below it, Extreme Programming in Layer 8 carries it out through continuous integration, and Little's Law in Layer 9 gives the arithmetic that links work in progress to lead time. The common mistake is asking a branching rule to fix a planning or quality problem. It exposes weak tests and unclear work faster, and fixing them remains the team's job.

How organizations put it to work

A head of engineering or a platform lead owns the change, but the working habit belongs to every developer. It changes structure little. It changes routines: daily merges, short code reviews, and a build that stops the line when it fails. It changes decisions: unfinished work is merged behind a flag, and releasing becomes a business choice instead of a technical event. It changes measures: the number of active branches, the age of the oldest unmerged change, and the time from commit to release. DORA's thresholds are three or fewer active branches, merging at least once a day, and no code freezes or integration phases.

Sustaining it takes a fast, trusted automated test suite, a rule for removing flags once a feature is released, and leaders who treat a broken build as the team's first priority.

In the first year, a leader should expect a dip in quality and morale while the tests catch up with the pace, complaints from developers who liked working alone, and a clear drop in time lost to merging. The business gains in the speed and predictability of releases, and in less dependence on the one person who knows how to resolve a difficult merge.

Where it goes wrong

The first failure is trunk without tests. Daily merging into a codebase with weak automated checks puts defects in front of everyone. The sign is a build that is often red and a team that has stopped looking at it.

The second is flag sprawl. Flags are easy to add and often forgotten, and each one multiplies the combinations that need testing. The site itself warns that flags tend to outlive their purpose, much as feature branches did. The sign is code full of conditions nobody dares remove.

The third is applying it where it does not fit. Products that must support old interfaces for a long time because customers choose their own upgrade dates, and teams too new to have any automated tests, will find the model costly. The sign is a team renaming its long branches as trunk and merging once a week.

Related and rival frameworks

  • Continuous Delivery and Continuous Deployment. The wider philosophy of keeping software always releasable. Trunk-based development is one of its enablers, and delivery is the better entry when the question is the whole path to production.
  • DORA Metrics. Measures the delivery performance this practice aims to improve. Use it to check whether the change helped.
  • Extreme Programming. Brings continuous integration and test discipline as part of a full method. It suits a team that needs the supporting engineering habits as well.

Go to the source

Back to the catalog