The Question Every Team Faces
You're scaling your engineering team. Do you stick with feature branches, or switch to trunk-based development? This isn't a religious debate—it's an engineering tradeoff with measurable consequences.
Feature Branching
Feature branches give each developer an isolated sandbox:
git checkout -b feature/user-authentication
# work for 2 weeks
git push origin feature/user-authentication
# open PR, wait for review, merge
Advantages:
- Code review before merge
- Isolated development
- Easy to abandon failed experiments
- Works well with GitHub/GitLab PR workflows
The hidden cost:
The longer a branch lives, the worse the merge gets. After two weeks, you're not merging code—you're resolving conflicts.
Merge hell timeline:
Day 1: 0 conflicts
Day 3: 2 conflicts
Day 7: 12 conflicts
Day 14: "I'm rewriting it from scratch"
Trunk-Based Development
Everyone commits to main multiple times per day:
git checkout main
git pull
# make small change
git commit -m "add null check to user lookup"
git push
# CI runs, deploys automatically
Branches exist but live for hours, not weeks.
The mechanics that make it work:
1. Feature Flags
if (featureFlags.isEnabled('new-checkout-flow', userId)) {
return <NewCheckout />;
}
return <LegacyCheckout />;
Ship incomplete features behind flags. Merge to main. Enable for 1% of users. Gradually roll out.
2. Branch by Abstraction
// Old interface
interface PaymentProcessor {
charge(amount: number): Promise<void>;
}
// New implementation runs in parallel
class StripeV2Processor implements PaymentProcessor {
async charge(amount: number): Promise<void> {
// new implementation
}
}
// Switch via config, not deployment
const processor = config.useStripeV2
? new StripeV2Processor()
: new StripeV1Processor();
3. Pair Programming / Small PRs
Trunk-based works best when:
- PRs are reviewed within hours, not days
- Changes are < 400 lines
- Pair programming reduces review overhead
The DORA Metrics Verdict
The DevOps Research and Assessment (DORA) report consistently finds:
| Metric | Feature Branches | Trunk-Based |
|---|---|---|
| Deployment frequency | Weekly/monthly | Multiple/day |
| Lead time for changes | Days/weeks | Hours |
| Change failure rate | 15-45% | 0-15% |
| Recovery time | Days | Hours |
Elite performers use trunk-based development.
When Feature Branches Make Sense
- Open source projects with external contributors
- Compliance requirements (every change needs sign-off)
- Teams with < 5 engineers who move slowly
- Major platform migrations requiring weeks of work
When Trunk-Based Makes Sense
- Product teams shipping frequently
- Microservices with independent deployments
- Teams practicing CI/CD seriously
- High-velocity startups
The Hybrid Approach Most Teams Actually Use
1. Short-lived feature branches (< 2 days)
2. Small PRs (< 200 lines ideally)
3. Feature flags for incomplete work
4. Automated tests gate every merge
5. Deploy on merge to main
This captures most of trunk-based's benefits while keeping PR-based code review.
Implementation Checklist
# Configure branch protection
git config branch.main.pushRemote no
# Set up pre-commit hooks
npx husky install
npx husky add .husky/pre-commit "npm test"
# Branch lifetime alerts (in CI)
if [ $(git log --oneline origin/main..HEAD | wc -l) -gt 20 ]; then
echo "Warning: Branch has 20+ commits. Consider merging sooner."
fi
The Real Question
It's not which approach is objectively better. It's: does your team have the discipline and tooling to make trunk-based work?
Feature flags, fast CI, and frequent integration are prerequisites—not nice-to-haves.
Start with short-lived branches. Measure your merge times. If they exceed 2 days consistently, you have a trunk-based problem wearing feature branch clothes.
Building automation tools for developers? Check out Whoff Agents — AI-powered MCP tools and starter kits for shipping faster.
Top comments (0)