View as Markdown

Using Queue Rules

Learn how to implement queue rules and route your pull requests.


Mergify’s multiple queue rules give you finer control over the merge process by categorizing pull requests based on any criteria you define.

Queue rules let you organize your PR merge process into separate templates, each with its own merge configuration.

With queue rules, you can:

  • Define multiple queues for different categories of PRs (e.g. dependencies vs. features).

  • Control merge methods (merge, squash, rebase, fast-forward, merge-batch) per queue.

  • Adjust batching behavior (batch size, max wait time).

  • Apply custom conditions for queuing and merging (labels, branch targets, CI checks, file paths, etc.).

Multiple queue rules are defined under the queue_rules key in your configuration file. Each rule needs a unique name and can have different configurations.

.mergify.ymlyaml
queue_rules:
- name: urgent
# Can be queued early if the PR has the urgent label
queue_conditions:
- label = urgent
# Still requires CI to pass before merge
merge_conditions:
- check-success = myci
- name: default
# Requires CI both for queueing and merging
queue_conditions:
- check-success = myci

A pull request goes to the first queue rule whose queue_conditions it matches, in the order the rules are written in the configuration. In the example above, a pull request labeled urgent whose myci check passed matches both rules and goes to urgent. Naming a queue with the name option of the queue action skips that order: the pull request goes to that queue once it matches that queue’s queue_conditions. When no rule’s queue_conditions match, the pull request is not queued, because there is no fallback queue. Mergify reports what each rule is still missing and queues the pull request once one of them matches.

Besides its queue_conditions, every queue rule checks the conditions your branch protections and rulesets require and the merge protection rules that apply to the pull request. So a rule can fail to match on a condition its queue_conditions do not list, such as a review or a check that a ruleset requires. The report of what a rule is still missing lists those conditions with the rest. See how condition injection works for what Mergify turns into conditions.

The top-level key queue_rules allows you to define the rules that govern your merge queue.

Here are all the available fields you can configure for a queue rule:

allow_inplace_checksboolean·defaulttrue·Deprecated#

Deprecated: this value is computed automatically.

Mergify checks a queued pull request in place, on its own branch and without a draft pull request, when all of these hold:

  • merge_queue.max_parallel_checks is 1
  • merge_queue.mode is serial
  • its queue rule's batch_size is 1 (the max, for a {min, max} range)
  • its queue rule's max_checks_retries is 0
  • its queue rule's merge_method is not merge-batch
  • its queue rule's CI is single-step: merge_conditions are empty or identical to queue_conditions

Even then, a batch built with several pull requests before batch_size was lowered to 1 is checked through a draft pull request.

Otherwise Mergify checks the pull request through a draft pull request, unless it can merge it without one: the pull request is first in the queue, its queue rule's CI is single-step, its merge_method is not merge-batch, and it is already up to date with its base branch or, unless its merge_method is fast-forward, behind it only by queue merges that touched none of its scopes.

batch_max_failure_resolution_attemptsinteger or null·defaultnull#

The number of attempts to resolve a batch failure before dequeueing pull requests. By default, Mergify will attempt to resolve a batch failure by splitting the batch multiple times until it finds the root cause of the failure. You can stop this process earlier by limiting the number of resolution attempts. Setting this to 0 will dequeue all the pull requests from a batch when a batch fails.

batch_max_wait_timeduration·default30 seconds#

The maximum amount of time to wait for additional pull requests before processing a batch that hasn't reached batch_size. The timer starts when the first pull request enters the batch. If batch_size is reached before this time expires, the batch processes immediately. This does not enforce a minimum delay between batches.

batch_sizeinteger or {min, max}·default1#

The number of pull requests per speculative check in the queue. Either a single integer (fixed size, 1-128) or an object {min, max} for dynamic batching: the queue uses min when parallel-check slots are plentiful and grows toward max to keep the backlog at zero.

branch_protection_injection_modequeue, merge or none·defaultqueue#

Branch protections conditions injection mode to use.

  • queue will inject branch protections conditions as required conditions for queuing and merging pull requests.
  • merge will inject branch protections conditions as required conditions only for merging pull requests.
  • none will not inject them at all, and requires a merge_bot_account able to satisfy the protections itself.
checks_timeoutduration, auto or null·defaultauto#

The amount of time the merge queue waits for pending checks to return before dequeueing pull requests. This cannot be less than 60 seconds. Defaults to auto, which lets Mergify compute the timeout from the recent CI runtime of this queue (the 95th-percentile runtime with a safety margin). Runs identified as retry reruns or bisection runs are excluded from the calibration; runs whose provenance predates this tracking are kept for compatibility. auto applies no timeout until enough history has been gathered. Set to null to disable the checks timeout entirely.

commit_message_format

CommitMessageFormatModel

or null·defaultnull
#

Declarative commit message format configuration.

draft_bot_accountBot account or null·defaultnull#

Mergify can impersonate a GitHub user to create its draft pull requests. If no draft_bot_account is set, Mergify creates the draft pull request itself. The user account must have already been logged in Mergify dashboard once and have admin, write or maintain permission.

max_checks_retriesinteger·default0#

Number of times Mergify will retry failed CI checks before removing the pull request from the queue. On each retry, the draft pull request is recreated to trigger a fresh CI run. This is useful for handling flaky CI. When set to a value greater than 0, in-place checks are disabled and a draft pull request is always created. Set to 0 (default) to disable retries.

merge_bot_accountBot account or null·defaultnull#

Mergify can impersonate a GitHub user to merge pull requests. If no merge_bot_account is set, Mergify merges the pull request itself. The user account must have already been logged in Mergify dashboard once and have write or maintain permission.

merge_conditions

List of conditions

#

The list of conditions to match to get the queued pull request merged. In case of draft pull request, the merge conditions for checks are evaluated against the temporary pull request instead of the original one.

merge_methodmerge, rebase, squash, fast-forward or merge-batch or null·defaultnull#

Merge method to use. If no value is set, Mergify uses the first authorized method available in the repository configuration.

Additionally, merge-batch merges the draft pull request prepared by the merge queue using a merge commit. A batch of a single pull request is then checked like any other batch, never in place on the pull request itself.

namestring#

Name of the queue rule.

queue_branch_prefixstring·defaultmergify/merge-queue/#

Prefix for the merge queue branch name. It must start valid git branch names, and cannot start with refs/, which GitHub refuses. Branches under this prefix are eligible for automatic queue branch cleanup.

queue_conditions

List of conditions

#

The list of conditions that needs to match to queue the pull request.

update_bot_accountBot account or null·defaultnull#

For certain actions, such as rebasing branches, Mergify has to impersonate a GitHub user. You can specify the account to use with this option. With no update_bot_account, the update goes through GitHub's API as Mergify and impersonates nobody. The user account must have already been logged in Mergify dashboard once. This option overrides the value defined in the queue rules section of the configuration.

Warning: With update_method: rebase and checks run in place, a pull request coming from a fork cannot be rebased on behalf of this account: GitHub refuses an OAuth token on its rebase API for a fork, so it would mean impersonating the account to force-push the contributor's branch. Those pull requests are refused when they are queued. Unset this option to rebase them through GitHub's API as Mergify instead -- except for a fork pull request that changes GitHub Actions workflows or was opened by another App's bot, which GitHub lets Mergify queue in place only with an update_bot_account, or that changes more files than GitHub lists, which Mergify cannot rule out as a workflow change; such a queue has to run its checks on a draft pull request. Or set update_method: merge on a queue that does not merge with fast-forward: such a queue lands by moving the base branch onto this one, so a merge commit is what it exists to keep off it, and it has to run its checks on a draft pull request instead.

update_methodrebase or merge or null·defaultnull#

Method to use to update the pull request with its base branch when the check is done in place. Possible values:

  • merge to merge the base branch into the pull request.
  • rebase to rebase the pull request against its base branch. When the queue runs its checks in place, a pull request coming from a fork cannot be rebased on behalf of an update_bot_account and is refused -- see that option for the remedy. Without an update_bot_account, the rebase goes through GitHub's API as Mergify, which works on a fork -- except for one that changes GitHub Actions workflows or was opened by another App's bot, which GitHub lets Mergify queue in place only with an update_bot_account, or one that changes more files than GitHub lists, which Mergify cannot rule out as a workflow change. Such a queue has to run its checks on a draft pull request instead.

When null, defaults to merge except if merge_method is fast-forward then it defaults to rebase.

The merge_method option controls how pull requests are merged into the base branch. Accepted values are merge, rebase, squash, fast-forward, and merge-batch.

Each method produces a different git history shape. See the Merge Strategies guide for a detailed comparison, including configuration examples and trade-offs.

  • queue_conditions → Requirements for a PR to be accepted into the queue. Example: a label, a CI check, or a branch filter.

  • merge_conditions → Requirements for a PR to be merged once it reaches the front of the queue. Example: all CI checks passed, required approvals.

This separation lets you schedule PRs early (e.g. based on labels) while still enforcing stricter checks before merge. This can be used to implement two-step CI.

You can find more details about the lifecycle of a pull request in the documentation.

Control auto-queueing with auto_merge_conditions in merge_protections_settings. It accepts true for unconditional auto-merge, or a list of conditions to restrict the audience.

Merge Protections must be enabled on the repository for auto_merge_conditions to take effect.

Was this page helpful?