TechTrailCamp
← Back to Blog

Trunk-Based Development Done Right

BRANCHING STRATEGIES COMPARED GitFlow main develop feature/big-feature (weeks) feature/another-feature (weeks) release/1.0 ⚠ = merge conflict Trunk-Based main (trunk) 1-2 days 1-2 days ■ = deploy Short-lived branches + frequent merges = fewer conflicts, faster feedback

Most teams start with GitFlow or some variation of long-lived feature branches. It feels safe — your main branch is always "clean." But as the team grows, the pain compounds: merge conflicts, integration delays, and the dreaded "merge day" before a release.

Trunk-Based Development (TBD) takes a different approach: everyone commits to a single shared branch (the trunk), with short-lived feature branches that last no more than a day or two. It's how Google, Facebook, Netflix, and most high-performing engineering teams work.

What is Trunk-Based Development?

Trunk-Based Development is a source-control branching model where developers collaborate on code in a single branch called "trunk" (or "main"). The core rules are simple:

  • One main branch — all code flows through trunk
  • Short-lived branches only — feature branches live for 1-2 days maximum
  • Small, frequent commits — integrate changes multiple times per day
  • Trunk is always releasable — every commit should be deployable
  • Feature flags over feature branches — hide incomplete work behind toggles

Why Long-Lived Branches Hurt

Long-lived feature branches create a false sense of safety. The longer a branch lives, the more it diverges from trunk, and the harder it becomes to merge. Here's what typically happens:

The Cost of Long-Lived Branches Branch Lifetime 1 day 1 week 1 month 3 months Merge Pain Easy merge Some conflicts Major conflicts Rewrite needed
Merge pain grows exponentially with branch lifetime — keep branches short
  • Merge conflicts multiply — the longer the branch, the more code has changed on trunk
  • Integration bugs surface late — you only discover incompatibilities at merge time
  • Code reviews become painful — reviewing 2,000 lines is much harder than reviewing 200
  • Deployment risk increases — big merges mean big deployments mean big risk
  • Team velocity drops — developers spend more time resolving conflicts than writing features

How Feature Flags Enable TBD

The biggest objection to TBD is: "But my feature isn't done yet — I can't merge incomplete code to main!" Feature flags solve this elegantly:

Feature Flags: Ship Code Without Shipping Features Developer Commits to trunk CI/CD Pipeline Build, test, deploy Production Code deployed Feature Flag Service new-checkout: OFF dark-mode: ON (10%) Result: • Code is in production • Feature is hidden from users • Can enable for % of users • Instant rollback (flip flag)
Feature flags decouple deployment from release — code ships to production but features activate separately

With feature flags:

  • Incomplete features are hidden — the code is in production but behind a flag set to OFF
  • Gradual rollouts — enable for 1% of users, then 10%, then 50%, then 100%
  • Instant rollback — if something breaks, flip the flag instead of rolling back a deployment
  • A/B testing — show different features to different user segments
  • Trunk stays clean — no long-lived branches needed

Implementing TBD: Practical Steps

1. Keep Branches Under 24 Hours

Create a branch, make your change, open a PR, get it reviewed, and merge — all within a day. If a feature takes a week, break it into 5 smaller PRs that each deliver a slice of the work.

2. Commit Small, Commit Often

Each commit should be a small, self-contained change. Aim for PRs under 200 lines of code. Small changes are easier to review, easier to test, and easier to roll back.

3. Invest in CI/CD

TBD requires a fast, reliable CI pipeline. Every commit to trunk should trigger:

  • Automated unit and integration tests
  • Static analysis and linting
  • Security scanning
  • Automated deployment to staging

If your CI pipeline takes 30+ minutes, developers will avoid committing frequently. Aim for under 10 minutes.

4. Use Feature Flags for Incomplete Work

Tools like LaunchDarkly, Unleash, or even a simple config file can manage feature flags. Start simple — a boolean flag in a config file is enough for most teams.

5. Practice Continuous Code Review

Small PRs enable fast reviews. Set a team norm: PRs should be reviewed within 2-4 hours. If a PR sits for days, the branch becomes long-lived — defeating the purpose.

Common Pitfalls to Avoid

  • Feature flags without cleanup — old flags accumulate as tech debt. Remove flags once a feature is fully rolled out.
  • Skipping tests — TBD without good test coverage is reckless. You need confidence that trunk is always deployable.
  • Big-bang migrations — even with TBD, some changes (like database migrations) need careful planning. Use expand-contract patterns.
  • Not investing in CI speed — slow pipelines kill TBD adoption. Parallelize tests, cache dependencies, use faster hardware.
  • Forcing TBD without buy-in — the team needs to understand why. Start with a pilot project and let the results speak.

TBD vs GitFlow: When to Use Each

Use Trunk-Based Development when:

  • You want to deploy frequently (daily or more)
  • Your team practices continuous integration
  • You have good test coverage and CI/CD
  • You're building a SaaS product or web application

GitFlow may still make sense when:

  • You maintain multiple versions simultaneously (e.g., on-premise software)
  • You have strict release gates (e.g., regulated industries)
  • Your deployment frequency is monthly or quarterly
Trunk-Based Development isn't about removing all branches — it's about keeping them short-lived. The goal is continuous integration: everyone's code is integrated into trunk multiple times per day.

Conclusion

Trunk-Based Development is a proven practice used by the world's highest-performing engineering teams. It reduces merge conflicts, accelerates feedback loops, and enables continuous delivery. The key enablers are short-lived branches, feature flags, fast CI/CD, and a culture of small, frequent commits.

Start small: pick one team, set a 24-hour branch limit, and invest in your CI pipeline. The results will speak for themselves.

At TechTrailCamp, we cover trunk-based development, CI/CD pipelines, and DevOps practices as part of our AWS + DevOps track. You'll learn to implement these practices in real-world projects.

Want to master DevOps and CI/CD?

Join TechTrailCamp's 1:1 training and learn modern development practices from a practicing architect.

Start Your Learning Journey