What is trunk-based development?
Answer
Trunk-based development (TBD) is a branching strategy where all developers commit to a single shared branch (usually main or trunk) at least once a day. Branches are short-lived (hours to days, not weeks) and merged back quickly. Key practices: (1) Small, frequent commits to main — no long-running feature branches; (2) Feature flags — incomplete features are hidden behind flags rather than living in separate branches; (3) Automated tests — fast test suite (minutes) that runs on every commit; (4) Branch by abstraction — for large refactors, create an abstraction layer first; (5) CI validates every commit immediately. Variants: pure TBD (commit directly to main) and scaled TBD (short-lived branches <2 days, always branched from and merged to main). Advantages: no merge hell (long-lived branches diverge significantly), smaller batches reduce risk, enables true CI/CD (continuous integration means integrating continuously), faster feedback. Who uses it: Google, Facebook, Netflix. Comparison: GitFlow is for teams doing periodic releases; TBD is for teams doing continuous deployment. TBD requires mature CI/CD, automated tests, and feature flag infrastructure.