CI guide
GitHub merge queue: how it works and how to set it up
What the queue actually tests, the one workflow trigger it can't work without, which settings decide how fast it drains, and what to check when a pull request keeps falling out of it.
A merge queue lets people (and agents) hand a pull request to GitHub and walk away: once it has passed its required checks, GitHub tests it again on top of the latest base branch and everything queued ahead of it, then merges it only if that combination passes. The base branch stays green without anyone rebasing and re-running CI by hand.
It matters most when many pull requests land on one branch each day. That is exactly what happens once coding agents open pull requests: dozens of small, independently green changes that were each tested against a main which has since moved on.
This guide follows GitHub's documentation as it stands today (linked under Sources). Availability and settings change, so check Managing a merge queue before you plan around them.
The problem it solves
Two pull requests can each pass CI and still break main together: one renames a function, the other adds a new call to the old name. Each was tested against the main it branched from, and neither against the other.
GitHub's older answer is the branch protection setting Require branches to be up to date before merging. It closes the gap, but every merge makes every other open pull request out of date, so authors rebase, wait for CI, and race each other to merge. With many pull requests a day, most CI runs are spent re-testing branches that lose the race.
A merge queue gives the same guarantee without the race. The author's part ends at "Merge when ready"; the queue does the updating and re-testing.
Who can use it
From GitHub's documentation:
- Merge queues are available in public repositories owned by an organization, and in private repositories owned by organizations using GitHub Enterprise Cloud. Repositories owned by a personal account don't get one. Check GitHub's plans for your own account.
- Repository administrators turn it on for a branch.
- Anyone with write access can add a pull request to the queue once it meets the branch's requirements.
How the queue tests a pull request
When a pull request joins the queue, GitHub builds a merge group: a temporary branch holding the latest base branch, the changes of every pull request ahead of it in the queue, and this pull request's changes. It then asks your CI to run the required checks on that branch.
Say pull requests #1 and #2 are queued for main, in that order:
- #1 is added. The queue creates a temporary branch with
mainplus #1 and requests checks. - #2 is added. The queue creates another with
mainplus #1 plus #2 and requests checks on it too, without waiting for #1's to finish. - When both report success, GitHub merges the second branch into
main, which now holds both pull requests.
If #1's group fails, #1 is removed from the queue and #2's group is rebuilt as main plus #2 alone, then tested again. Pull requests leave the queue in first-in, first-out order, and the base branch only ever receives a combination that passed.
The temporary branches live under the gh-readonly-queue/<base branch>/ prefix and have a different commit SHA from the pull request itself, which is why your CI must test them as their own thing.
Step 1: make your workflows run on merge_group
This is the step most setups miss. Checks that ran on the pull request do not count for the merge group: the queue waits for the required checks to be reported on the merge group's commit. A GitHub Actions workflow only runs there if it listens for the merge_group event, which is separate from pull_request and push.
Add it to every workflow that reports a required check:
on:
pull_request:
branches: [main]
merge_group:
types: [checks_requested]
branches: [main]
checks_requested is the only activity type Actions supports today; naming it keeps the workflow specific if GitHub adds more. The branches filter matches the target branch of the merge group, so branches: [main] means "groups that will merge into main".
Without the trigger, nothing reports the required check on the merge group, the queue waits until its timeout, and the pull request is removed. Do this before you turn the queue on.
Inside the workflow, GITHUB_SHA and GITHUB_REF are the merge group's commit and ref. A step that should only run in the queue, or only on the pull request, can test the event name:
- name: Slow end-to-end suite
if: github.event_name == 'merge_group'
run: npm run test:e2e
That split is a common way to keep pull-request feedback fast and spend the long suite once, on the exact commit that is about to land. A job skipped by an if: condition reports success, so make sure the job that does run in the queue is the one carrying the required check's name.
With another CI provider
A CI system other than Actions needs to run on pushes to branches starting with gh-readonly-queue/<base branch> (for example gh-readonly-queue/main) and report its status to that commit. A CI integration built as a GitHub App can subscribe to the merge_group webhook instead, which also sends a destroyed action when a group is merged, dequeued or invalidated, so you can cancel work on a group that will never land.
Step 2: require the merge queue on the branch
A repository administrator turns on Require merge queue in the branch protection rule (or ruleset) for the base branch, alongside the required status checks. GitHub's notes:
- A merge queue can't be enabled on a branch protection rule whose name pattern uses a wildcard (
*). - The checks the queue waits for are the same required checks the pull request must pass; they are configured together.
Once required, the merge button on a pull request becomes Merge when ready.
The settings that decide how fast it drains
With the requirement on, these settings appear beside it:
| Setting | What it does |
|---|---|
| Merge method | Merge, rebase or squash for queued pull requests |
| Build concurrency | How many merge groups GitHub dispatches for CI at once (1 to 100); caps your concurrent CI builds, and with them how fast the queue moves |
| Only merge non-failing pull requests | On: every pull request must pass on its own. Off: a pull request that failed can still merge as part of a group whose last pull request passed, which is GitHub's suggestion when flaky tests would otherwise hold up the queue |
| Status check timeout | How long the queue waits for CI before treating the checks as failed |
| Merge limits | The minimum and maximum number of pull requests merged into the base branch at once (1 to 100), and a wait time after which a smaller group merges anyway |
Two points that are easy to get wrong:
- Merge limits don't combine builds. Each queued pull request still gets its own merge-group run; the limits only decide how many already-passing groups are merged into the base branch together. A maximum helps when every merge triggers a deploy; a minimum helps when post-merge CI is long.
- Build concurrency is the throughput dial. Too low and the queue waits on CI one group at a time; too high and you pay for many speculative runs that are thrown away when an earlier group fails. Set the status check timeout comfortably above your slowest required job, or slow runs will read as failures.
Adding and removing pull requests
- In the browser: Merge when ready, then Confirm merge when ready. You can press it before the checks have passed; GitHub turns on auto-merge and queues the pull request once its requirements are met, even if auto-merge is off for the repository. Disable auto-merge cancels that wait.
- From the command line:
gh pr mergeon a branch that requires a queue adds the pull request to it, or enables auto-merge if its checks haven't passed yet. The GraphQLenqueuePullRequestmutation queues it only if it can go in now, and returns an error saying why when it can't. That is the easier call for an agent or bot, which should know immediately rather than leave a pull request waiting. - To remove one: Remove from queue on the pull request, or the … menu on the branch's merge queue page. The GitHub CLI can't remove a pull request from the queue, nor show the queue.
- To see the queue: the repository's Branches page, or the merge queue link at the bottom of a queued pull request.
When adding a pull request you can also choose to jump to the top of the queue. Use it sparingly: GitHub notes that it forces a full rebuild of every merge group already in progress, because each now needs the jumping pull request underneath it.
Why a pull request was removed
GitHub removes a pull request from the queue, and says why on its timeline, when:
- a required check fails on its merge group;
- CI didn't report a result before the status check timeout;
- someone removed it, in the interface or through the API;
- a branch protection requirement failed in a way the queue couldn't resolve, or its changes conflict with the base branch.
When one pull request is removed, every group built on top of it is rebuilt and re-tested without it, which is why a single flaky test can stall a busy queue.
When the queue gets stuck
| Symptom | Likely cause |
|---|---|
| Every pull request times out in the queue | A workflow that reports a required check has no merge_group trigger, so the check is never reported on the merge group |
| One required check sits at "Pending" | The workflow was skipped by a path or branch filter. GitHub's advice is not to require a workflow that can be skipped; make the required job run every time and decide inside it what to test |
| A required check is missing after a failed job | A job that needs a failed job is skipped and may not block merging; GitHub suggests always() with needs for required checks that depend on other jobs |
| Pull requests keep getting removed, then pass on retry | Flaky tests. Fix or quarantine them; turning off "Only merge non-failing pull requests" lets a later passing group carry an earlier failure |
| The queue moves one pull request at a time | Build concurrency is low, or merge groups are slow; check the status check timeout against your slowest job |
| Third-party CI never reports | It isn't building gh-readonly-queue/* branches |
Measure the queue, not just the run
A queue adds a wait between "approved" and "merged" that doesn't show up in any single workflow run. When you tune it, time a pull request from Merge when ready to merged, and split that into time waiting for a CI runner, time running checks, and time spent re-testing after another pull request was removed. Our piece on measuring commit-to-verdict time separates queue wait from run time in the same way, and the GitHub Actions cache guide covers keeping the runs themselves short.
The queue keeps main green; it doesn't review the changes for you. When agents are opening the pull requests, the review step in front of the queue is usually the slower one, and the GitHub CODEOWNERS guide covers routing each change to the people who must approve it.


