Git, CI/CD & GitOpsXXIX · Branching StrategiesStrategies
Trunk-based development — committing to the trunk every day
What you'll learn
- Articulate the trunk-based contract: small commits to the trunk at least daily, hidden behind feature flags when incomplete
- Identify the infrastructure-code analogues of feature flags
- Recognise the four disciplines that make trunk-based safe
Prerequisites
Verified against Git 2.55.x teaching target; 2.40+ minimum · GitHub Actions continuous service; Aug 2026 documentation baseline · Argo CD v3.5.x teaching target; v3.0+ minimum · Flux v2.9.x · Sigstore Cosign v3.1.x · SLSA v1.2 · OCI Distribution Specification v1.1 · Git LFS v3.7.1 · Kubernetes (cross-course target) 1.36.x
Trunk-based development is the strategy that aligns with modern CI. The contract: every engineer commits to the trunk at least daily, hides incomplete work behind a flag, and keeps the trunk deployable at any moment. There are no long-lived feature branches. The trunk is the integration surface.
For an infrastructure team, the trunk is the source of truth the GitOps controller reads; every commit is a candidate for the next sync. The discipline is to keep the trunk deployable, to hide incomplete changes behind a flag, and to merge small and often.
The trunk-based contract
The contract has four clauses. (1) Commits land on the trunk at least daily — a branch living more than one working day is long-lived and drifts. (2) The trunk is always green — a commit that breaks is reverted within minutes, not fixed forward. (3) Incomplete work is hidden behind a flag: code is in the trunk, behaviour is not. (4) Small commits, fast CI — each commit changes one thing and the CI runs in minutes.
flowchart LR
T1["commit a"] --> T2["commit b"]
T2 --> T3["commit c"]
T3 --> T4["commit d"]
F1["flag login-v2 = off"] -.-> T2
T4 -->|"CI green"| D["deployable"]
The diagram shows the trunk-based shape: a single linear chain where every commit hides incomplete behaviour behind a flag, and the trunk’s tip is always deployable.
Why it fits modern CI
The integration cost rises with the gap between forks. Two engineers who fork on Monday and merge on Friday have four days of divergence; two who merge daily have at most one day. For an infrastructure repository, the integration cost is paid by the GitOps controller: drift between fork and trunk is drift between the engineer’s view and the cluster’s view.
Four disciplines hold the strategy together: small commits (one field is easy to revert, fifty is not); fast CI (forty-minute CI erodes the “always green” property); feature flags with lifecycles (every flag has an owner and removal date); revert over fix-forward (a revert is one commit, a fix-forward can be many).
Production discipline
- Default branch is the integration surface. Treat
mainaccordingly: small commits, fast CI, fast revert. - Incomplete work is hidden behind a flag. Gate by config toggle or environment gate.
- Revert over fix-forward. A broken commit is reverted within minutes.
- Audit flag lifecycles. Stale flags are deleted on a quarterly cadence.
- Document the strategy. The branching strategy is in
CONTRIBUTING.md.
Cross-course references
- GitOps with Argo CD - Part IV (SyncPatterns) covers auto-sync with prune and self-heal.
- CI/CD Pipeline Patterns - Part III (FastCI) covers the fast-CI discipline trunk-based requires.
- Terraform for Production Sysadmins - Part XI (PRWorkflows) covers the Terraform analogue of flags.
Quiz
Knowledge check · 4 questions
Q1. A team's CI takes forty minutes per plan and feature branches live for four days. What is the most important blocker to trunk-based?
Q2. Trunk-based development forbids feature branches entirely.
Q3. Name the four disciplines that hold trunk-based together.
Q4. Diagnose trunk-based degrading from stale flags.
A team adopted trunk-based six months ago. Every feature lands behind a flag. An audit reveals forty-seven flags, twenty-three in production for more than ninety days with no removal ticket, three orphaned.
Passing score: 75%. Answers are checked in this browser.