Merge Queues
Avoiding conflicts and keeping trunk green.
What is a merge queue?
A merge queue is a tool that tries to automatically maintain a repository of code that always passes tests. Merge queues accomplish this by validating code changes in a stable order before merging them into a trunk branch. By enforcing a pre-merge order, merge queues eliminate skew and reduce semantic conflicts. Without the help of some merge queue, semantic conflicts break trunk branches in repositories more and more frequently as the repositories scale. At a high enough rate of committers, it becomes practically impossible to “keep trunk green” without a merge queue.
Most merge queues intercept the traditional big green “merge” button on PRs and replace it with some “enqueue” action. From there, the merge queue re-executes CI tests, with each change rebased in order. As code changes in the queue pass the order-enforced testing, they're automatically merged into the desired trunk branch.
Merge queues effectively ensure that CI still passes at the moment of merge regardless of how long the PR has been open. However, some engineers dislike anything that slows down the time to merge - and even the most advanced merge queues will create some slowdown while CI runs. This cost is a necessary evil as the number of committers scales, but it can be mitigated. Teams that care about speed should leverage features such as batching, parallel CI, and partitioning to keep changes merging as fast as possible. Most modern merge queue solutions offer some set of these features.