Trunk-Based Development Cheat Sheet

Trunk-based development — short-lived branches, daily merges to main, feature flags, and CI/CD practices for high-velocity teams.

Last Updated: May 1, 2025

Core Practices

ItemDescription
Short-Lived BranchesBranches exist for hours, not days — merge to main at least daily
Small CommitsEach commit is small, atomic, and passes all tests
Feature FlagsIncomplete features ship to production behind toggles
Comprehensive TestingFast test suite runs on every commit before merge
Code ReviewEvery commit is reviewed — pair programming counts as review
Continuous DeploymentMain is always deployable — deploy multiple times per day
No Long-Running BranchesNo develop, no release branches — just main
Release TagsTag specific commits on main for release identification

Branch Workflow

git checkout -b short-fix main
Create very short-lived branch from main
git commit -m 'Fix: correct validation logic'
Small, focused commit
git fetch origin main && git rebase origin/main
Rebase on latest main before merging
git push -u origin short-fix
Push and open PR immediately
gh pr create --fill
Create PR with auto-filled description
gh pr merge --squash --delete-branch
Squash merge and clean up branch
git checkout main && git pull
Update local main after merge
git branch -d short-fix
Clean up local branch

Feature Flags

ItemDescription
Launch DarklyManaged feature flag service with targeting and analytics
Environment VariablesSimple flags via env vars: FEATURE_NEW_UI=true
Config File FlagsYAML/JSON config flags for moderate complexity
Trunk-Based + FlagsShip code immediately; enable feature when ready
A/B TestingUse flags to roll out features to percentage of users
Kill SwitchesEmergency flags to disable features without redeploying
Flag CleanupRemove flag code after feature is fully rolled out and stable
OperatorsPer-team, per-user, percentage-based, and date-scheduled rollouts

TBD vs Other Models

AspectTrunk-BasedGitHub FlowGitFlow
Branch LifespanHoursDaysWeeks to months
Main Branches1 (main)1 (main)2 (main + develop)
Release CadenceContinuousContinuousScheduled
Merge FrequencyDaily+Every few daysWhen feature complete
ComplexityLowLowHigh
Best ForCI/CD, DevOpsWeb apps, SaaSMobile, packaged software
Pro Tip: The key to TBD is small, frequent merges. If your branches live more than a day, you're doing it wrong. Pair with feature flags for incomplete work.