Skip to content
← Back to merge queue guideMerge queue guide

Merge Queue vs Direct Merging

Direct merging lands each pull request on its own green check, tested against the main it last saw. A merge queue tests every pull request against the latest main plus the ones queued ahead of it and merges only what passes. Nobody updates a branch by hand.

By Julien Danjou, Co-founder & CEO of MergifyUpdated

What counts as direct merging?

Any setup where a pull request merges on the strength of its own CI run. Someone, or a bot, presses merge once the checks on the pull request are green, and nothing tests the combined result before it reaches main. On GitHub it comes in two variants, set by one checkbox under required status checks.

Merge on green

“Require branches to be up to date before merging” is off, which GitHub calls loose status checks. A pull request can merge as soon as its checks pass, even if main has moved since they ran. Its CI tested the pull request against the main it branched from or last updated to, and by merge time that can be dozens of commits old. GitHub's documentation says it plainly: “Status checks may fail after you merge your branch if there are incompatible changes with the base branch.”

Merge on green, branch must be up to date

The same checkbox is on, which GitHub calls strict. A pull request can only merge if its branch contains the latest commit on main, so its checks ran against exactly what it lands on. That closes the gap. In exchange, every merge moves main and puts every other ready pull request out of date at the same moment, and each one has to be updated and run through CI again before somebody else's merge makes it stale once more. GitHub's docs put it mildly: “More builds may be required.”

Auto-merge sits on top of either variant. It merges a pull request “after all required reviews and status checks pass,” which saves the click and inherits the branch's setting: stale but green on a loose branch, update after every merge on a strict one.

How can two green pull requests break main?

When both were tested against a main that no longer exists. Here is a rename on a Python service that merges on green:

Mon 16:00  #318 renames get_user() to fetch_user()
           and updates every caller.            CI green
Mon 17:30  #322 adds app/exports.py, which
           imports get_user.                    CI green
Tue 09:05  #318 merges. No conflict.
Tue 09:40  #322 merges. No conflict: new file.
Tue 09:41  main: ImportError: cannot import name
           'get_user' from 'app.users'

Both reviews were right and both checks were honest. #322 was tested on Monday's main, which still had get_user(), and nothing ran it again after #318 removed that name. Git compares lines of text, and the two pull requests touched different files, so it had nothing to report. This is a semantic conflict, and the first place the two changes ever ran together was main, after both had merged.

The strict variant catches this one. At 09:05 #318 merges and #322 falls behind, someone clicks “Update branch”, CI runs on main plus #322, the import fails, and #322 never lands. It also costs more than it looks as soon as more than one pull request is waiting.

How many CI runs does “branch must be up to date” cost?

Take five pull requests that are approved and green at 09:00. Main has moved since their last runs, so all five are behind, and CI takes 20 minutes. Everyone clicks “Update branch”, the first run to finish merges, and that merge makes the other four stale again:

RoundPull requests updated and re-runOne merges at
1509:20
2409:40
3310:00
4210:20
5110:40
Total15 CI runs100 minutes

Assumes every run passes and someone clicks “Update branch” the moment main moves. Real days are slower.

For N pull requests ready at once, that is N + (N−1) + … + 1 = N(N+1)/2 runs. Five pull requests cost 15 runs and twenty cost 210, because the pull request that lands last gets rebuilt once per round.

Racing does not even buy speed. Only one pull request can merge per round, however many rebuild, so the fifth lands at 10:40 either way. Taking turns brings the run count down to five, but then someone has to watch main and update the next pull request the moment the previous one merges, and every minute nobody is watching is added to everyone's wait. In both versions a person is babysitting the merge button.

How is a merge queue different?

A merge queue runs the check the strict setting asks for and takes the person out of the loop. An approved, green pull request joins the queue, through auto-merge or a comment such as @mergifyio queue. The queue tests it on the latest main plus every pull request ahead of it. A pass merges it, and a failure removes it from the queue with main untouched. Nobody updates a branch by hand, because the queue builds the combined state itself.

Same five pull requests at 09:00. The queue tests #1 on main, #2 on main + #1, #3 on main + #1 + #2, and so on, all at once, betting that the ones ahead will pass (speculative checks). When they do, all five land around 09:20 for five CI runs instead of fifteen. With batching, the five can share a single run. If #2 fails, it leaves the queue and the runs stacked on top of it restart without it, with nobody clicking anything.

In the rename example, #322 is tested on main + #318 and fails with the ImportError inside the queue, so it never reaches main. GitHub describes its own merge queue in the same terms: it “provides the same benefits as” the up-to-date requirement, without making authors update their branches and wait.

Merge queue vs direct merging: how do they compare?

The rows with numbers reuse the five pull requests and 20-minute CI from above, with every run passing.

QuestionDirect mergeDirect merge, branch must be up to dateMerge queue
What CI actually testedEach pull request on the main it last sawEach pull request on the latest mainEach pull request on the latest main plus the ones ahead of it
Can two green pull requests break main?YesNoNo
CI runs to merge N ready pull requestsNone beyond the runs they already hadN if people take turns, N(N+1)/2 if they raceN, fewer with batching
CI runs for 5 ready pull requests05 to 155, or 1 with batch_size: 5
Fifth pull request lands (20-minute CI)Right awayAbout 100 minutes in, plus reaction timeAbout 20 minutes in, testing in parallel
Who babysits the merge buttonNobody, until main goes redThe authors, after every mergeNobody
SetupNothingOne checkboxA queue: GitHub's built-in one or a dedicated tool

The middle column is correct and free, and its cost grows with the square of the number of pull requests waiting. That growth is the whole case for a queue.

What does a merge queue cost, and how do you keep it small?

A queue has costs of its own. Four show up in practice, and each has a known fix:

  • Latency. Every pull request waits for one queue run after approval, 20 minutes in the example. Testing pull requests in parallel, each stacked on the ones ahead (speculative checks), keeps that wait near one run when several are queued. On a quiet day Mergify can skip the queue run entirely when the pull request at the front already contains the tip of main (Direct Merge).
  • CI bill. Queue runs come on top of pull request CI. Batching tests several pull requests in one run and splits the batch to find the culprit when it fails. Two-step CI keeps the cheap checks on the pull request and runs the expensive suite only in the queue, once per change that is about to land.
  • Contention in a monorepo. One queue for a whole monorepo makes a docs fix wait behind a database migration it shares nothing with. Parallel queues give independent parts of the repository their own lanes.
  • Failures. When a pull request fails in the queue, everything tested on top of it restarts, so a flaky test costs every pull request behind it a re-run. Queue failure rate is the number to watch once the queue is in place.

With Mergify, a starting point is about a dozen lines of .mergify.yml. Batching is set explicitly here. Parallel checks are on by default, up to five at once, through merge_queue.max_parallel_checks.

queue_rules:
  - name: default
    queue_conditions:
      - "#approved-reviews-by>=1"
      - check-success=ci
    merge_conditions:
      - check-success=ci
    batch_size: 5
    merge_method: squash

merge_protections_settings:
  auto_merge_conditions: true

Replace check-success=ci with the name of your own CI check. Setting up a merge queue on GitHub walks through the rest, and the queue rules reference lists every key. Choosing between GitHub's built-in queue and a dedicated one is its own question: see merge queue tools and Mergify vs GitHub merge queue.

When is direct merging good enough?

More often than merge queue vendors like to admit (we are one). The race grows with the square of N, so it is negligible while N is small: two pull requests waiting at once cost three runs, and nobody ever opened a ticket over three runs. Direct merging with the up-to-date requirement turned on is enough when:

  • Rarely more than one or two pull requests are ready at the same time.
  • Main moves a few times a day. The merge queue guide puts the line at around five pull requests a day.
  • One team owns the repository, so a break on main gets noticed and reverted within minutes.
  • Nobody times their merges or waits for a quiet moment to press the button.

Fast CI makes each round cheaper and leaves the shape of the problem alone. Do I need a merge queue if my CI is fast? works through that case. Once people start rebasing and re-running CI just to get a merge in, a queue costs less than the people doing its job by hand.

FAQ

What is the difference between a merge queue and direct merging?

Direct merging lands a pull request on the strength of its own CI run, which tested it against the main it branched from or last updated to. A merge queue tests each pull request against the latest main plus the pull requests ahead of it and merges it only if that run passes. It does the updating and the ordering itself.

What does 'Require branches to be up to date before merging' do?

It is a GitHub branch protection option under required status checks. With it on, a pull request can only merge if its branch contains the latest commit of the base branch, so its checks ran against what it lands on. In exchange, every merge puts every other open pull request out of date, and each one has to be updated and tested again before it can merge.

Is a merge queue the same as requiring branches to be up to date?

It gives the same guarantee. GitHub's documentation says its merge queue provides the same benefits as that setting without requiring authors to update their branches. Queues also do what the manual version cannot: test several pull requests at once, each stacked on the ones ahead, and batch them into a single CI run.

How many CI runs does the up-to-date requirement cost?

With N pull requests ready at once, between N runs if people take turns and N(N+1)/2 runs if everyone updates after every merge. Five pull requests cost 5 to 15 runs and ten cost 10 to 55. A merge queue needs N runs, or fewer with batching.

Does a merge queue slow merging down?

Each pull request waits for one queue run before it lands, so on a quiet repository a queue adds about one CI duration. On a busy one it is usually faster than updating branches by hand, because the queue tests pull requests in parallel instead of one round at a time. Mergify can also skip the queue run when the pull request at the front already contains the tip of main.

Can I use GitHub auto-merge instead of a merge queue?

Auto-merge saves the click and changes nothing else. It merges once required reviews and checks pass, so it inherits the branch's settings: without the up-to-date requirement two green pull requests can still break main, and with it the branch still has to be updated after every merge before it can land.

When is direct merging good enough?

When one or two pull requests are ready at a time and main moves a few times a day. A small team on one repository can turn on the up-to-date requirement and skip the queue. Add one when people start rebasing and re-running CI just to get a merge in.

Full reference: parallel checks and batches in the Mergify docs, and about protected branches on GitHub.

Stop clicking “Update branch”.

Mergify tests every pull request on the latest main plus the ones ahead of it, and merges it when CI passes. It runs on the CI you already have.