Dev tools
Trunk Based Development: How It Works in Practice
Trunk based development explained: how it works, trunk based development vs GitFlow, feature flags, release branches, a worked example and how to adopt it.
Trunk based development is a source-control practice in which every developer integrates small changes into one shared main branch, the trunk, at least once a day, instead of working for weeks on long-lived feature branches. Work stays releasable at all times: automated tests run on every change, unfinished features hide behind feature flags, and releases are cut from the trunk. Google's DORA research lists it as a key capability of high-performing software teams, because it avoids painful merges and lets teams deliver continuously.
This guide explains how trunk based development works day to day, trunk based development vs GitFlow and GitHub flow, trunk based development with feature flags and with release branches, the prerequisites, a worked trunk based development example, the evidence behind it, and how to adopt it without breaking production.
What Is Trunk Based Development?
The "trunk" is the single shared branch everyone integrates into, usually called main or master in Git. In trunk based development:
- developers commit small changes to the trunk frequently, at least daily;
- any branches are short-lived, typically hours or a day or two, then merged and deleted;
- the trunk is always in a working, deployable state, protected by automated tests;
- incomplete features are hidden with feature flags or other techniques rather than kept on separate branches.
DORA, the long-running research program on software delivery now part of Google Cloud, describes the practice in measurable terms. Teams achieve higher delivery and operational performance when they have three or fewer active branches in the repository, merge branches to trunk at least once a day, and don't have code freezes or integration phases.
There are two common styles:
- Direct-to-trunk: small, experienced teams commit straight to
main, relying on pair programming and strong tests. - Short-lived branches with pull requests: the more common style in larger teams; each change gets a branch, a quick review and automated checks, then merges to trunk within a day or so.
How Trunk Based Development Works
A typical day for a developer:
- Pull the latest trunk first thing and work from it.
- Make a small, self-contained change: a refactor, one slice of a feature, a test, a bug fix.
- Run tests locally, then push to a short-lived branch.
- Open a small pull request. Because it's small, review takes minutes, not days.
- CI runs automatically on the change: build, unit tests, integration tests, linting, security checks.
- Merge to trunk once checks pass and a reviewer approves. Many teams use a merge queue so each change is tested against the latest trunk before it lands.
- Deploy: the trunk is deployed automatically, or released on a schedule, with unfinished features switched off by flags.
The key habit is slicing work small. A two-week feature becomes ten or twenty mergeable steps, each of which leaves the trunk working.
Trunk Based Development vs GitFlow
GitFlow, described by Vincent Driessen in 2010, uses several long-lived branches: main for releases, develop for integration, plus feature, release and hotfix branches. It was designed for software shipped in versions, where several releases may be supported at once.
| Trunk based development | GitFlow | GitHub flow | |
|---|---|---|---|
| Long-lived branches | Just trunk (plus optional release branches) | main and develop, plus release and hotfix branches | Just main |
| Feature branch lifetime | Hours to a day or two | Days to weeks or longer | Short to medium |
| Integration frequency | Continuous, at least daily | When features are finished | When each pull request is merged |
| Unfinished work | Hidden behind feature flags | Kept on feature branches | Kept on branches until ready |
| Release process | Deploy trunk continuously, or cut release branches from trunk | Release branches stabilised, then merged to main and develop | Deploy main |
| Merge conflicts | Small and frequent | Large and painful near releases | Moderate |
| Best fit | Continuous delivery, web services, teams with strong CI | Versioned software with several supported releases | Small teams and web apps |
Driessen himself added a note to his original post in 2020: web apps are typically continuously delivered, and for teams doing continuous delivery he suggested adopting a much simpler workflow, like GitHub flow, instead of shoehorning GitFlow into the team. GitFlow still suits products such as desktop or embedded software where several versions are maintained in parallel.
GitHub flow and trunk based development are close cousins. The difference is mostly emphasis: trunk based development insists on very short branch lifetimes and daily integration, and uses feature flags so large features never need long-lived branches.
Trunk Based Development With Feature Flags
Trunk based development with feature flags is what makes the practice work for large features. A feature flag is a runtime switch that turns a code path on or off without a new deployment.
if flags.is_enabled("new-checkout", user=current_user):
return new_checkout(cart) # merged to trunk, hidden from most users
return old_checkout(cart)Flags let teams:
- merge incomplete work safely, because it's switched off in production;
- separate deployment from release: code ships continuously, and the business decides when users see it;
- roll out gradually to internal users, then a small percentage of customers, then everyone;
- kill a bad feature instantly without a rollback deployment.
Flags have costs. Each one adds a branch in the code and a configuration to test. Teams that never remove flags accumulate "flag debt": confusing, half-dead code paths. Give every release flag an owner and a removal date, and delete it once the feature is fully launched.
Trunk Based Development With Release Branches
Not every team deploys continuously. Mobile apps go through app-store review, and enterprise software ships on schedules. Trunk based development with release branches handles this:
- When a release is due, create a release branch from trunk, for example
release/2.14. - Test and ship from that branch.
- Fix bugs on trunk first, then cherry-pick the fix to the release branch. Never develop on the release branch and merge back, which reintroduces long-lived divergence.
- Delete or archive the release branch when that version is no longer supported.
Release branches are created by release managers, not developers, and receive only cherry-picked fixes. Day-to-day development stays on trunk.
Other Techniques That Keep the Trunk Releasable
- Branch by abstraction: to replace a large component, introduce an interface in front of the old implementation, build the new implementation behind it in small steps, switch callers over, then delete the old one, all on trunk.
- Dark launching: deploy new backend code and send it real traffic in the background without showing results to users, to test performance safely.
- Keystone interfaces: build the back end of a feature first and add the user-facing entry point (the "keystone") last, so the feature is invisible until it's complete.
- Small, reversible database changes: expand the schema first, migrate code, then contract, so every step works with both old and new code.
Prerequisites for Trunk Based Development
Trunk based development removes the safety net of isolation, so it needs other safety nets:
| Prerequisite | Why it matters |
|---|---|
| Fast, reliable CI on every change | Broken code must be caught within minutes, before others pull it |
| A strong automated test suite | Unit, integration and a focused set of end-to-end tests guard the trunk |
| Quick code review | Small changes waiting days for review defeat the purpose |
| A merge queue or required up-to-date checks | Ensures each change is tested against the latest trunk |
| Feature flags | Lets large features merge before they're finished |
| Fast rollback or fix-forward | Mistakes reach production sooner, so recovery must be quick |
| Team habits | Slicing work small and integrating daily is a skill teams build deliberately |
Our guide to end-to-end testing covers how to build the top layer of that safety net without making CI slow.
Trunk Based Development Example
Here's a trunk based development example. A team adds a new checkout flow, which would take about two weeks on a long-lived branch. Instead:
| Day | Change merged to trunk | Visible to users? |
|---|---|---|
| 1 | Add the new-checkout feature flag (off) and an empty new checkout module | No |
| 1 | Refactor the payment client behind an interface (branch by abstraction) | No |
| 2 | Build the new cart summary component with unit tests | No (flag off) |
| 3 | Add the new address form and validation | No |
| 4 | Wire the new flow to the payment interface; integration tests added | No |
| 5 | Turn the flag on for employees only; dogfooding begins | Internal users |
| 6 | Fix two bugs found internally, each merged within hours | Internal users |
| 7 | Enable for 5% of customers; watch error rates and conversion | 5% |
| 9 | Enable for 50%, then 100% | Everyone |
| 12 | Remove the flag and the old checkout code | Everyone, old path gone |
The trunk was releasable every day. No change took more than a few hours to review, conflicts with other teams' work were caught within a day, and the risky moment was a flag flip that could be reversed instantly, not a giant merge the night before release.
Benefits and Evidence
- Fewer, smaller merge conflicts. Integrating daily means conflicts are caught while they're small. Our guide to git merge conflicts shows how much easier small conflicts are to resolve.
- Continuous integration in practice. DORA calls trunk based development a required practice for continuous integration: if code isn't merged frequently, it isn't really integrated.
- Faster feedback. Bugs surface within hours of being written, not weeks later in a stabilisation phase.
- No code freezes. Without big integration events, there's no need to stop work before releases.
- Better delivery performance. DORA's research finds that teams following these practices achieve higher software delivery and operational performance, meaning delivery speed, stability and availability.
- Proven at scale. Many large engineering organisations, Google among them, develop on a shared trunk with heavy automated testing and code review.
Challenges and When It's Hard
- Weak test coverage. Without good automated tests, merging to trunk daily spreads breakage quickly.
- Slow reviews or approvals. Heavyweight review processes, which DORA calls out as a common pitfall, push developers back toward long-lived branches.
- Regulated environments. Change approval processes may need redesigning around automated evidence rather than manual sign-off per release.
- Distributed open source. Projects with occasional outside contributors often rely on longer-lived forks and pull requests; trunk principles apply more loosely.
- Flag sprawl. Feature flags need lifecycle management or they become a source of bugs.
- Culture. Developers used to finishing a whole feature before sharing it need practice slicing work and showing incomplete (but switched-off) code.
How to Adopt Trunk Based Development
- Measure where you are: count active branches and how long they live, and track how often code reaches
main. - Strengthen CI first: fast builds, reliable tests, required checks on
main, and a merge queue if conflicts are common. - Set a branch lifetime target, such as "merged within two days", and make it visible.
- Introduce feature flags with a simple tool or library and a policy for removing them.
- Shrink pull requests: agree on size guidelines and fast review expectations, measured in hours.
- Retire the `develop` branch if you're coming from GitFlow; make
mainthe integration point. - Practise recovery: make rollback and fix-forward routine so mistakes are cheap. Our site reliability engineering guide covers the operational side.
FAQ
Is trunk based development better than GitFlow?
For teams that deploy continuously, usually yes: it integrates work sooner, avoids big merges and fits continuous delivery. GitFlow can still make sense for software released in versions with several supported releases at once.
Does trunk based development mean no branches?
No. Most teams use short-lived feature branches and pull requests that merge within a day or two, plus optional release branches cut from trunk. What it avoids is long-lived development branches.
How do you handle unfinished features?
With feature flags, branch by abstraction and keystone interfaces. Code merges to trunk switched off, so users don't see it until it's ready.
Can large teams use trunk based development?
Yes. It requires strong automated testing, fast CI, merge queues and disciplined, small changes, but many large organisations work this way.
How often should you merge to trunk?
At least once a day per developer, according to DORA's guidance. Many teams merge several times a day.