Course contentsShow
← Software Engineering
Lesson 646 of 1,93320. Continuous IntegrationFree lesson

Working on the Trunk vs Feature Branches

Trade-offs between trunk-based development and feature branching in the context of CI.

Working on the Trunk vs Feature Branches

What you'll learn: How to weigh the trade-offs between committing directly to trunk (main branch) versus developing on isolated feature branches in a CI environment.

The Core Choice

When practicing Continuous Integration, teams face a fundamental branching decision. Trunk-based development means everyone commits to the main branch (often called main or trunk) multiple times per day, integrating work continuously. Feature branching means developers create separate branches for each feature, merging back to main only when complete—sometimes after days or weeks.

Trunk-Based Development

This approach keeps the codebase unified. Since you're committing small changes frequently (as you learned in "The Practice of Small Commits" and "Committing to Mainline Frequently"), integration problems surface immediately. The CI server verifies every commit against the latest code, catching conflicts within hours, not days.

The trade-off: Everyone sees your work-in-progress. You must use feature flags or other techniques to hide incomplete features from users.

Feature Branching

Creating a branch per feature feels safer—you work in isolation without disrupting others. You can take your time polishing before merging.

The trade-off: The longer your branch lives, the further it drifts from trunk. When you finally merge, you face a painful "integration tax"—conflicts, broken tests, and incompatible assumptions. This delays feedback and violates CI's core principle of integrating early and often.

The CI Perspective

True Continuous Integration favors trunk-based development. Feature branches that live for days become integration branches, not CI. The feedback loop slows down, defects hide longer, and the "integrate early" principle breaks down.

Key Takeaway: Trunk-based development maximizes CI benefits by providing immediate feedback and preventing integration debt, while long-lived feature branches delay integration and reduce the effectiveness of continuous verification.