Sobes.tech
Middle

How do approaches Trunk-Based Development and Feature Branching differ?

sobes.tech AI

Answer from AI

Criterion Trunk-Based Development (TBD) Feature Branching (FB)
Main branching One main branch (trunk/main/master) Multiple long-lived branches (develop, release, master)
Merge frequency Very frequent (at least once a day) Rare (after feature completion)
Feature branch size Very short-lived (from minutes to hours) Long-lived (from days to weeks)
Integration Continuous integration (CI) is key Integration occurs less frequently and can be more complex
Conflict risk Fewer major conflicts, but more minor, frequent ones More major conflicts when merging large branches
Release time to production Fast and frequent releases (continuous delivery) Slower and less frequent releases
Testing requirements High level of automated testing Tests may be performed later in the cycle
Team size Suitable for small to medium teams but scalable with discipline Suitable for large teams

Trunk-Based Development:

  • Focus on frequent integration of small changes directly into the main branch.
  • Requires strict discipline, automated tests, and feature flags to manage incomplete features.
  • Reduces risks associated with large merges.

Feature Branching:

  • Each feature is developed in a separate branch.
  • Merging occurs only after feature completion.
  • Can lead to "branch sinking" and complex conflicts if branches live long.

Example code for TBD (simplified):

// Development is done directly in main/trunk
public class FeatureA {
    public void doStuff() {
        // Feature A code
    }
}

// Another developer commits to main/trunk almost simultaneously
public class FeatureB {
    public void doOtherStuff() {
        // Feature B code
    }
}

Example code for FB (simplified):

// Developer 1 works in branch feature/A
// git checkout -b feature/A develop
public class FeatureA {
    public void doStuff() {
        // Feature A code
    }
}

// Developer 2 works in branch feature/B
// git checkout -b feature/B develop
public class FeatureB {
    public void doOtherStuff() {
        // Feature B code
    }
}

// After completing feature A, branch is merged into develop
// git checkout develop
// git merge feature/A

// After completing feature B, branch is merged into develop
// git checkout develop
// git merge feature/B // Conflicts may occur with code from feature/A
How do approaches Trunk-Based Development and Feature… - sobes.tech