Trunk-Based Development (TBD) Rollout Plan
Overview: Trunk-Based Development emphasizes frequent, small commits directly to the main branch (trunk) to minimize integration risks, enable continuous delivery, and foster collaboration. This rollout plan introduces TBD incrementally over 8-12 weeks, focusing on four pillars: branch policy, merge queue, flake triage, and small PR coaching.
Goals:
- Reduce merge conflicts by 80%.
- Achieve <1 day trunk lifetimes for branches/PRs.
- Cut flaky test rates to <1%.
- Increase PR merge frequency by 3x.
Assumptions:
- Git-based repo (e.g., GitHub/GitLab/Bitbucket).
- Existing CI/CD (e.g., GitHub Actions, Jenkins, CircleCI).
- Team buy-in via kickoff workshop.
Team Roles:
- TBD Champions (2-3 engineers): Lead rollout, monitor metrics.
- Everyone: Adopts practices progressively.
Phase 1: Preparation (Weeks 1-2)
- Kickoff Workshop (1 hour): Explain TBD benefits (faster feedback, fewer bugs). Demo trunk state.
- Metrics Baseline:
| Metric | Tool | Target |
|---|
| Branch lifetime | GitHub Insights | <24h |
| PR size (lines changed) | GitHub PR stats | <400 |
| Flake rate | CI logs | <1% |
| Merge conflicts | GitHub merge logs | 0% |
| Deploy frequency | CD pipeline | Daily |
- Tools Setup:
- Enable branch protection on
main (require PRs, status checks).
- Install merge queue tool (e.g., GitHub Merge Queue beta, Bors, or Mergify).
- Set up Slack/Teams bot for flake alerts.
- Success Criteria: Metrics dashboard live, 100% team trained.
Pillar 1: Branch Policy
Goal: Enforce short-lived branches, feature flags for incomplete work.
Policy Rules (Enforced via GitHub/GitLab Rulesets)
- No long-lived branches: Auto-delete branches >24h post-merge. Block pushes to
main directly.
- Feature branches only: Prefix
feature/team-shortdesc (e.g., feature/auth-login). Max 1 dev/branch.
- Feature Flags (FFs): All unfinished features behind FFs (e.g., LaunchDarkly, Unleash). No FF = must merge to trunk.
- Hotfix branches:
hotfix/severity-desc (e.g., hotfix/prod-outage). Merge immediately.
- Release branches: Rare; only for stabilization (e.g.,
release/v1.2). Merge back to trunk ASAP.
Rollout (Phase 2: Weeks 3-4)
- Week 3: Announce policy in README + team all-hands. Enable GitHub ruleset: require
/trunk-ready label + 1 approval.
- Week 4: Audit existing branches; force-merge/delete old ones. Champions review 100% of PRs for compliance.
- Enforcement:
# GitHub Branch Protection Rule
- Require PR before merging
- Require status checks: CI, lint, security
- Require linear history (rebase only)
- Dismiss stale approvals on push
- Restrict pushes to admins only
- Metrics: Track branch age. Alert on >12h branches.
- Gotchas: Train on
git rebase vs. merge. Use git switch -c for branches.
Success: 90% branches <24h.
Pillar 2: Merge Queue
Goal: Serialize PR merges to trunk, avoiding conflicts/flakes.
Setup
Rollout (Phase 3: Weeks 5-6)
- Week 5: Pilot with 20% of team (opt-in). Champions merge via queue.
- Week 6: Mandate for all PRs targeting
main. Block direct merges.
- Handling Conflicts: Queue auto-rebases; if fails >3x, require trunk sync.
- Metrics: Queue wait time (<15min), conflict rate (0%).
- Fallback: Manual rebase for complex PRs.
Success: 100% merges via queue, conflicts <1%.
Pillar 3: Flake Triage
Goal: Eliminate flaky tests blocking trunk.
Process
- Detect: CI marks flakes (same test fails >20% runs). Bot posts to Slack: "Flake detected: testXYZ [link]".
- Triage (Daily 15min standup):
| Priority | Action | Owner |
|---|
| P0 (blocks prod) | Quarantine + fix same day | Author |
| P1 (frequent) | Reproduce locally, fix in 24h | Test owner |
| P2 (rare) | Log + ignore | Champions |
- Quarantine: Disable test, add ticket. Run in "flake mode" nightly.
- Root Causes: Race conditions → retries. Env issues → Docker isolation.
Rollout (Phase 4: Weeks 7-8, Parallel to Others)
Success: Flake rate <1%, zero P0s.
Pillar 4: Small PR Coaching
Goal: <400 LoC/PR, merge 5x/day/person.
Guidelines
- Size: Aim <100 adds, <50 deletes. Split large changes.
- Single Responsibility: One feature/bug per PR.
- Title Template:
[feat/bugfix/chore]: Short desc (#ticket).
- Body: What/Why/How + screenshots.
Rollout (Ongoing, Starts Phase 2)
- Coaching:
| Format | Frequency | Content |
|---|
| 1:1s | Bi-weekly | PR review w/ champion |
| Pairing | On-demand | Squash large PRs |
| Async | PR comments | "Split? 🎯 <400 LoC" |
| Workshop | Week 3 | "PR Squash Demo" |
- Gamification: Leaderboard for smallest/frequent PRs (Slack bot).
- Tools:
git diff --stat pre-PR. VSCode extension for LoC count.
- Anti-Patterns:
- ❌ Monolith PRs → Block w/ ruleset (<1000 LoC max).
- ❌ Unfinished work → Enforce FFs.
Success: Avg PR size <300 LoC, 3+ PRs/eng/day.
Phase 5: Sustain & Iterate (Week 9+)
- Retro: Bi-weekly. Adjust policies.
- Advanced:
- Trunk-only (no branches) for green teams.
- Blue-green deploys.
- Observability: Trunk health dashboard.
- Risks & Mitigations:
| Risk | Mitigation |
|---|
| Resistance | Incentives (e.g., "TBD Stars") |
| CI Cost | Parallel flakes only |
| Legacy Code | Gradual FF migration |
- Global Rollout: Replicate to other repos/teams.
Contact: Ping TBD Champions for Qs. Let's keep trunk green! 🟢
Trailblazer Labs – Innovating at the speed of trunk.