Module 8 Lesson 5: Trunk-Based Development
·DevOps

Module 8 Lesson 5: Trunk-Based Development

The peak of velocity. Learn Trunk-Based Development—the workflow used by the world's most elite engineering teams to deploy code hundreds of times per day.

Module 8 Lesson 4: Trunk-Based Development

We've seen workflows that use lots of branches (Git Flow) and workflows that use a few branches (GitHub Flow). Now, let’s look at the "Final Boss" of Git strategies: Trunk-Based Development (TBD).

In TBD, developers merge small, frequent updates to a single "trunk" (the main branch) at least once a day. This is the strategy used by companies like Google, Netflix, and Amazon.


1. The Core Philosophy

The primary goal of TBD is to eliminate the "Merge Hell" that happens when a branch lives for too long. If you merge your code every 4 hours, your conflicts will be tiny and easy to fix. If you wait 4 days, your conflicts will be a nightmare.

Key Rules:

  • Small Commits: You don't commit whole features; you commit the "bones" of a feature piece by piece.
  • No Long-Lived Branches: Branches should rarely live longer than 24 hours.
  • Feature Flags: Because half-finished code is being merged into main, you use "Feature Flags" (if/else statements in your code) to keep that code hidden from users until it’s actually ready.

2. TBD vs. Everything Else

WorkflowBranch LifespanMerge FrequencyRisk of Conflict
Git FlowWeeksMonthlyExtremely High
GitHub FlowDaysDailyModerate
Trunk-BasedHoursSeveral times per dayExtremely Low
graph LR
    Trunk["Main Trunk"]
    D1["Dev A (2 hrs)"] -- "Merge" --> Trunk
    D2["Dev B (4 hrs)"] -- "Merge" --> Trunk
    D3["Dev C (1 hr)"] -- "Merge" --> Trunk
    
    Trunk --> Deploy["Continuous Deployment"]

3. The prerequisites for TBD

You cannot do Trunk-Based Development unless you have:

  1. Perfect Automated Testing: Since code goes to main instantly, your tests must be 100% reliable at catching bugs.
  2. Fast Build Pipeline: If your tests take 2 hours to run, you can't merge every hour.
  3. Elite Communication: The team must always be in sync about what parts of the "Trunk" are being modified.

Module 8 Comprehensive Practice Exercises

Let's act as a "Workflow Consultant" for different companies:

  1. Scenario A: A bank is building a mobile banking app. They release one update every 3 months and must strictly follow government regulations. Which workflow should they use? (Git Flow).
  2. Scenario B: A startup is building a new social media site. They want to be able to fix bugs instantly and ship new features as soon as they are typed. They have 3 developers. Which workflow should they use? (GitHub Flow).
  3. Scenario C: A massive tech company has 5,000 developers working on a single search engine. They want to ensure no two developers ever work on stale code. Which workflow should they use? (Trunk-Based Development).
  4. Scenario D: You are working alone on a hobby project. You don't care about "Reviews" or "Releases." Which workflow is simplest? (Centralized Workflow).

Checkpoint: If you could correctly identify why each company chose their workflow, you have mastered the strategy of Git!


Summary

In this lesson, we established:

  • Trunk-Based Development focuses on high-frequency, small merges.
  • It uses Feature Flags to hide half-finished work on the main branch.
  • It is the fastest possible way to ship software but requires the highest level of technical maturity.

Module Complete! You now know how professional teams organize their work around the world.

Next Module: Commands and strategies are the "Logic" of Git. Welcome to Module 9: Collaboration Best Practices, where we’ll learn the "Etiquette" and soft skills of working with others.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn