Field notes. Opinions are marked as opinions.
A branch is a private copy of the code. That is all it is. The longer you keep a private copy, the further it drifts from what everyone else is doing, and the bill for that drift arrives on the day you merge. Trunk-based development is the practice of keeping branches so short-lived, usually a day or two at most, that the drift never gets large enough to hurt.
What it actually is
There is one shared line of development, called trunk, main or master. Everyone merges into it at least daily. Branches, if used at all, last hours. Nobody has a “release branch” for features still being built, and nobody sits on a two-week branch called feature/new-checkout.
Contrast that with the branching style many Indian service teams inherit: a develop branch, per-feature branches, a release branch, a hotfix branch, and a person whose real job is “merge manager”. It looks organised. It is organised, in the way a customs queue is organised.
Why long branches hurt
Take an illustrative team of six, each on their own branch for three weeks. Merge conflicts are the visible problem, and they are the smaller one. The worse problem is semantic conflict: two changes that merge cleanly in text and break each other in behaviour. One person renames a field; another adds a new screen using the old name. Git sees no conflict. The build fails, or worse, it passes and production fails.
There is also the review problem. A 40-line pull request gets read. A 2,500-line one gets a comment saying “looks good” after ten minutes, because nobody has the stamina. Big branches produce shallow reviews. That is my opinion, but I have seldom seen it contradicted by how review actually behaves.
“But my feature takes three weeks”
The objection is always the same: unfinished work cannot go to trunk because trunk must stay releasable. Correct, and that is why the practice comes with tools for hiding unfinished work.
- Feature flags. The new code ships to production switched off. Merging is no longer the same thing as releasing. You turn the flag on for staff, then 5 percent of users, then everyone.
- Branch by abstraction. To replace a component, first put an interface in front of the old one, merge that, build the new implementation behind the same interface over several merges, and switch over at the end.
- Small slices. Add the database column first (unused), then the API field, then the screen. Each step is safe to deploy alone.
Flags are not free. Every flag is a branch in your runtime code, and old flags rot. Put an owner and a removal date on each one, or in a year you will have fifty flags and no one who knows which are safe to delete.
What trunk-based development demands
This is the part advocates sometimes skip. Merging to trunk daily is only sane if a broken merge is caught within minutes. That means:
- An automated build and test run on every merge, fast enough (ten minutes or so) that people do not bypass it.
- A team norm that a red trunk is fixed or reverted first, before anything else. A broken trunk left alone for an afternoon blocks everyone.
- Tests people actually trust. If the suite is flaky, developers learn to ignore failures, and the whole model collapses.
If you have no automated tests, do not adopt this on Monday and call it a strategy. You will simply be breaking production faster. Build the safety net first, or at least alongside.
Where I would not insist on it
Some situations genuinely favour other models. Open-source projects with many untrusted contributors use forks and pull requests because they cannot give strangers commit rights; that is a trust problem, not a branching preference. Teams shipping versioned software that must support several old versions in the field, such as a desktop product or an on-premise banking package, do need maintenance branches for those versions. Even there, new work still lands on trunk first and is back-ported.
Pull requests are not forbidden either. Short-lived branches with a quick review before merging are compatible with the idea. What the practice rejects is the branch that lives for weeks, not the review.
A way to try it without a revolution
Measure first. How old is your oldest open branch? How long does a typical pull request wait for review? Then set one small rule: no branch older than three days without a conversation. Break work into slices to fit that rule. See what hurts. What hurts will be the missing tests, the slow build or the review habits, and those were already problems; long branches were only hiding them.
Figures and names in the examples are illustrative.
Leave a Reply