Sub topic 4
Turning on the merge queue
This chapter shows how to enable a merge queue on a branch. You can use a classic branch protection rule or a repository ruleset. It assumes you already know how to read a workflow file, that your repository has required status checks, and that you can edit repository settings (admin access, or a custom role with that permission). The next chapters cover how the required checks run in the queue and how to tune each setting. Here the goal is a queue that is switched on and correctly attached to one branch.
Check that your repository is eligible
Merge queue is not available everywhere. Before you look for the setting, confirm the following:
- The repository belongs to an organization. Repositories owned by a personal account cannot use merge queue.
- The repository is public, or it is private on a plan that includes merge queue (GitHub Enterprise Cloud for private repositories).
- You can change settings for the target branch. Rules protecting a branch are managed under Settings for the repository.
If the option is missing, the cause is almost always plan or ownership, not a permissions mistake on your side.
Choose between a branch protection rule and a ruleset
GitHub gives you two places to turn the queue on. Both attach the queue to a branch, and both produce the same queue behavior. They differ in how you manage and reuse the configuration.
| Aspect | Branch protection rule | Repository ruleset |
|---|---|---|
| Where | Settings, Branches | Settings, Rules, Rulesets |
| Branch targeting | One name pattern per rule | Include and exclude lists, plus patterns such as the default branch |
| Layering | A branch can match several rules, and their restrictions combine | Several rulesets can apply, and the most restrictive setting wins |
| Bypass | "Allow specified actors to bypass" or admin settings | A bypass list with roles, teams, or apps |
| Dry run | Not available | An "Evaluate" mode on plans that support it |
| Automation | REST and GraphQL for branch protection | REST endpoint for rulesets, with a JSON body you can store in Git |
For a new setup, prefer a ruleset. It can be exported, reviewed, and applied to many branches. Use a branch protection rule when your repository already manages protection that way and you do not want two systems side by side.
Keep one system per branch where you can. When a branch is covered by both, GitHub applies the combined restrictions, and a stray rule left in either place is a common cause of confusing merge behavior.
Enable the queue with a ruleset
- Open the repository, then Settings, then Rules, then Rulesets.
- Select New ruleset, then New branch ruleset.
- Give it a name such as
main-merge-queue. - Set Enforcement status to Active. A ruleset left as Disabled does nothing.
- Under Target branches, add the branch. Use Include default branch or add a pattern such as
main. - Under Branch rules, tick Require a pull request before merging and Require status checks to pass. Add your checks.
- Tick Require merge queue. The queue settings appear below it.
- Select Create.
The queue is now attached to main. Pull requests that target it no longer merge directly. They enter the queue instead.
Enable the queue with a branch protection rule
- Open Settings, then Branches.
- Under Branch protection rules, select Add rule, or edit the existing rule for your branch.
- Enter the branch name pattern, for example
main. - Tick Require a pull request before merging.
- Tick Require status checks to pass before merging and select the checks.
- Tick Require merge queue. The queue settings appear below it.
- Select Create or Save changes.
Once the queue is on, the setting Require branches to be up to date before merging no longer does useful work. The queue itself builds each change on top of the latest base, so that setting does not need to be on. Leaving it on does not break the queue.
What the queue settings mean at creation time
Both paths show the same settings. You can leave the defaults at first, and the later chapter on choosing settings explains how to tune them. For this chapter you only need to know what each one controls.
| Setting | What it controls | Typical starting value |
|---|---|---|
| Merge method | How the queue lands the change: merge commit, squash, or rebase | Match your existing repository convention |
| Build concurrency | How many merge group branches the queue builds and tests at once | 5 |
| Minimum group size | The fewest pull requests the queue combines into one group | 1 |
| Maximum group size | The most pull requests the queue combines into one group | 5 |
| Wait time to meet minimum group size | How long the queue waits for more entries before it builds a smaller group | 5 minutes |
| Status check timeout | How long the queue waits for required checks on a group before it removes the group | 60 minutes |
Choose the merge method first, because it affects your history. With Squash, each pull request becomes one commit on main, and the queue produces that commit for you. The queue uses the method you set here. Individual authors cannot override it per pull request once the queue is enabled.
The ruleset also carries a grouping strategy. It decides whether a group needs every entry to pass or only the last one. The default is the safer setting, and the grouping chapter covers when to change it.
Check required checks before you tell the team
A queue attached to a branch only works if the required checks can report on the queue's temporary commits. Those commits come from the merge_group event, not from pull_request. If a required check's workflow lacks the merge_group trigger, the check never reports on the queue commit. The group waits until the timeout and is then removed.
Before turning the queue on for a busy branch, open each workflow that provides a required check and confirm it contains this trigger:
on:
pull_request:
branches: [main]
merge_group:
types: [checks_requested]Because checks_requested is the only activity type for this event, writing merge_group: with no types is equivalent. The next chapter goes through this trigger in detail.
Verify the configuration from the command line
You can confirm that the queue is attached without clicking through settings. The GitHub CLI can list the rulesets on a repository. Replace OWNER and REPO with your own values.
gh api repos/OWNER/REPO/rulesets --jq '.[] | {id, name, enforcement}'To read the full rules of one ruleset, pass its numeric id:
gh api repos/OWNER/REPO/rulesets/RULESET_ID --jq '.rules[] | select(.type == "merge_queue")'If the second command prints nothing, the ruleset does not contain a merge_queue rule. A queue enabled through a classic branch protection rule does not appear in this list, so check Settings, Branches for those.
Confirm it works with a test pull request
Do this on a low-risk change, such as a documentation edit.
- Open a pull request against the protected branch and wait for its checks to pass.
- Look at the merge box. The usual merge button is replaced by Merge when ready (or Add to merge queue, depending on whether checks have finished).
- Select it. The pull request enters the queue and shows its position.
- Open the Actions tab. A workflow run for the
merge_groupevent appears on a branch namedgh-readonly-queue/main/pr-<number>-<sha>. - When the checks pass, the queue merges the change into
mainand closes the pull request as merged.
If step 4 never happens, the required workflow does not trigger on merge_group. That is the first thing to fix.
Common mistakes when enabling the queue
- Ruleset left on Disabled. The ruleset exists but enforces nothing, so pull requests still merge directly.
- Pattern does not match the branch. A rule for
maindoes not covermasterorrelease/*. - Required checks added without
merge_group. The queue waits for checks that never report, then removes the group at the timeout. - Admins bypassing the queue. Anyone on the bypass list can merge directly and skip testing against the latest base. Keep the list short and intentional.
- Both a rule and a ruleset configured differently. Combined restrictions can produce results neither author expected. Remove the duplicate.
Exercise
A team enables "Require merge queue" on main with one required check named "test". Their "test" workflow has on: pull_request. A developer adds a green pull request to the queue. Thirty minutes later it is still waiting, and nothing appears in the Actions tab for the gh-readonly-queue branch. What is wrong, and what is the fix?
Show answer
The workflow does not run on the mergegroup event, so the required "test" check never reports on the temporary queue commit. Add `mergegroup: (optionally with types: [checks_requested]) to the workflow's on` block and merge that change. Without it, the group will wait until the status check timeout and then be removed from the queue.
Exercise
You enabled a queue through a ruleset, but pull requests still merge directly into main. Name two settings you would check first.
Show answer
Check that the ruleset's enforcement status is Active rather than Disabled, and that its target branch pattern actually matches main. Also check whether the person merging is on the ruleset's bypass list.