Quick revision
The short answer
The root problem is branch lifetime, so the main change is to break work into small pieces that merge within a day or two, with unfinished features behind feature flags. Around that, protect main: require a passing CI build and a review before any merge, and use a merge queue so the exact merged result is tested before it lands. Until branches are short, merge main into them frequently. Then measure branch age and lead time to show the change is working.
What to remember
In this answer, we saw that three-week branches break main because they integrate late and clash with weeks of other changes. We fixed it by splitting work into small changes behind feature flags, protecting main with required CI and review, syncing branches with main until they are short, and using a merge queue so main only receives tested merged results, and we measured branch age and lead time to show progress.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The root problem is branch lifetime, so the main change is to break work into small pieces that merge within a day or two, with unfinished features behind feature flags. Around that, protect main: require a passing CI build and a review before any merge, and use a merge queue so the exact merged result is tested before it lands. Until branches are short, merge main into them frequently. Then measure branch age and lead time to show the change is working.
Why this question is asked
When merges regularly break main, the cost is not just the broken build. Everyone who pulls main inherits the failure, deployments stop, and people start to fear merging, which makes branches live even longer. Interviewers ask this scenario because it combines process and tooling: tools alone will not fix three-week branches, and a process change without tooling will not hold. In this answer, we will see why long branches break main, then go through the fixes in order of impact: smaller changes with flags, branch protection, keeping branches current, merge queues, and finally measurement.
1Why Long-Lived Branches Break Main
A branch that lives three weeks is tested against main as it was three weeks ago. Meanwhile, other developers merge changes to the same classes, the same database migrations and the same configuration. When the long branch finally merges, two things can happen. There are textual conflicts, resolved in a hurry by someone who no longer remembers every detail. Or, worse, the merge is textually clean but semantically broken: one branch renamed a property in application.yml while the other added code reading the old name. Each side passed CI alone; together they fail.
The bigger the branch, the more of these interactions it contains, and they grow faster than the size of the branch, because every change on it can clash with every change on main. That is why the fix starts with size.
2Fix 1: Smaller Changes Behind Feature Flags
The highest-impact change is to make branches small. Instead of one branch for the new checkout, we split the work into pieces that each make sense alone and can be merged in a day or two: add the new table, add the new service behind a flag, add the new controller endpoint behind the same flag, switch the UI, remove the old path. Each piece is merged to main and deployed, turned off.
A feature flag is a runtime switch that decides whether the new code runs. It lets unfinished work live safely on main. This is a change in how people plan work, so it needs support: help with splitting stories in planning, a simple flag library, and an agreement that a pull request should usually be reviewable in under half an hour, often around 200 to 400 changed lines.
3Fix 2: Protect Main With Required Checks and Reviews
Next, make it impossible to merge something that does not build. Branch protection, a setting on the repository host, can require that a pull request has a passing CI run and at least one approving review before it can merge, and that the branch is up to date with main. Direct pushes to main are blocked for everyone.
This alone stops failures from untested merges, but it does not stop the semantic clash between two pull requests that were each green against an older main. That is what the merge queue is for.
4Fix 3: Keep Branches Current Until They Are Short
While the team is learning to make smaller changes, some branches will still live for days. The rule then is to bring main into the branch often, at least daily, with git merge origin/main or by rebasing on main, so conflicts are discovered while they are small and fresh, and the branch's CI run tests it against recent code. This is a mitigation, not the goal: a branch that needs daily syncing for three weeks is still a large risk at the end.
5Fix 4: Use a Merge Queue
Even with up-to-date branches, two pull requests can pass CI separately and break main together if they merge one after the other. A merge queue, such as GitHub's merge queue or GitLab's merge trains, solves this. When a pull request is approved, it joins a queue. The queue creates a temporary branch containing main plus the queued changes ahead of it plus this one, runs CI on that exact combination, and only merges if it passes.
6 messages in order. Play them, or step through them one at a time.
If CI fails, the PR leaves the queue and main never sees the broken combination.
Notice what changed: main only ever receives a commit that CI has tested in its final merged form. If the combination fails, the pull request is removed from the queue and its author is told, and main stays green.
6Measuring the Change
Process changes need evidence, both to keep the team motivated and to convince sceptics. Two numbers are easy to collect from the repository host. Branch age, the time from a branch's first commit to its merge, should fall from around 21 days towards one or two. Lead time for changes, from first commit to running in production, should fall with it. We also track how often main is red and for how long. Showing these on a simple chart at each retrospective turns the change from an opinion into a visible trend.
| Measure | Before | Target |
|---|---|---|
| Median branch age | about 21 days | 1 to 2 days |
| Lines changed per PR | often 2,000 or more | usually under 400 |
| Main broken per week | several times | rarely, fixed within an hour |
| Lead time to production | weeks | a day or less |
7Follow-up questions
Is rebasing better than merging main into the branch?
Both bring the branch up to date. Rebasing gives a linear history but rewrites the branch's commits, which is awkward if others share the branch. Merging is safer for shared branches. Either is fine as long as it happens often; the bigger win is short branches that rarely need it.
What if a feature truly cannot be split?
Almost every feature can be split technically, even if the user sees it only at the end: schema first, then backend behind a flag, then API, then UI. Branch by abstraction, putting an interface in front of the old code and building the new implementation behind it, helps for large refactorings.
Do merge queues slow down merging?
Each merge waits for one more CI run, but queues test several pull requests together in batches, so throughput stays good. Compared with the time lost when main is broken for the whole team, the wait is cheap.
8Conclusion
In this answer, we saw that three-week branches break main because they integrate late and clash with weeks of other changes. We fixed it by splitting work into small changes behind feature flags, protecting main with required CI and review, syncing branches with main until they are short, and using a merge queue so main only receives tested merged results, and we measured branch age and lead time to show progress.
Open with
The real problem is the three-week lifetime, so that is what I would attack first. A branch that old is tested against a main that no longer exists, and when it merges, it clashes with weeks of other work, sometimes textually and sometimes in ways that merge cleanly but break behaviour.
Then, if they want more
So I would work with the team to split features into small changes that merge within a day or two, things like schema first, then a service behind a feature flag, then the endpoint, so unfinished work can live on main switched off.
Then I would protect main with branch protection: no direct pushes, a green CI build and an approving review required for every merge. Until branches are short, people should merge main into their branch at least daily so conflicts are found while they are small.
To stop two green pull requests from breaking main together, I would turn on a merge queue, which runs CI on main plus the queued changes and only merges the exact tested result.
Finally I would measure branch age, pull request size, how often main is red and lead time, and show the trend in retrospectives, so the team can see the change working.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Maven guides, Gradle user manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your team's feature branches live for three weeks and merges regularly break main. What...": https://scrivio-interview-library.netlify.app/java/version-control-and-ci/659c27c25c/