GitHub merge queue API: enqueue, dequeue and read the queue
Short answer: you can add a pull request to the queue from the REST API (PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge-async with "merge_action": "merge_queue") or from the GraphQL API (the enqueuePullRequest mutation). To remove it (dequeuePullRequest) or read the queue (repository.mergeQueue(branch:)), GitHub’s docs only show GraphQL. Your CI hears about queued changes through the merge_group event. The queue itself has to be enabled on the branch first.
Disclosure up front: I built Queue to Main, a merge queue GitHub App for private repos on the Team plan, so I have an interest in merge queues. Everything about GitHub’s API below comes from GitHub’s own docs, read on 2026-11-17; links are in Sources. The examples follow GitHub’s reference; I haven’t run them against a live GitHub merge queue (Queue to Main doesn’t use one).
Before you call it
- The queue must be on. A merge queue is required on a branch through branch protection or a ruleset (rulesets can be set from the REST API too: the rules endpoints have a
merge_queuerule type, “Merges must be performed via a merge queue”). Each pull request has two Boolean fields you can check first:isMergeQueueEnabled(“whether the pull request’s base ref has a merge queue enabled”) andisInMergeQueue. - Who can queue: GitHub’s docs: “Once a pull request has passed all required branch protection checks, a user with write access to the repository can add the pull request to the queue.” The token you call the API with needs that access.
- Node IDs, not numbers (GraphQL). The mutations take the pull request’s GraphQL ID, not its number. With the GitHub CLI:
gh pr view 123 --json id -q .id.
Add a pull request with REST
GitHub’s REST reference has “Merge a pull request asynchronously”: PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge-async, which “merges a pull request into the base branch in the background or adds it to a merge queue”. It takes the pull request’s number, not a node ID. The body field merge_action decides: merge_queue adds the pull request to a merge queue, direct_merge merges without one, and default (also what you get if you leave it out) “uses a merge queue if one is configured for the target branch, or merges directly otherwise”. sha is the head commit the pull request must still match; without it, the current head is used, and a push between the request and the merge cancels it.
gh api -X PUT repos/your-org/your-repo/pulls/123/merge-async \
-f merge_action=merge_queue -f sha="$(gh pr view 123 --json headRefOid -q .headRefOid)"
- Responses: 202 with a UUID when the request is accepted; 200 if the pull request is already merged or already in a merge queue; 400 if it can’t be merged (closed, still a draft); 409 if another asynchronous merge request is already pending for it. The docs add that branch protection and repository rules “are not run at this stage”.
- The result:
GET /repos/{owner}/{repo}/pulls/{pull_number}/merge-async/{uuid}returnspending,merged,enqueuedorfailed.enqueuedis final: it means the pull request joined the queue, “not that it has merged”, and it doesn’t change when the queue later merges it. Results are kept for 24 hours. - The older endpoint
PUT …/pulls/{pull_number}/merge“does not support stacked pull requests or merging with a merge queue”.
Add it with GraphQL
enqueuePullRequest (“Add a pull request to the merge queue”) takes pullRequestId (required), expectedHeadOid (the head commit you expect, so you don’t queue a branch someone just pushed to), and jump (“Add the pull request to the front of the queue”). It returns the new mergeQueueEntry.
gh api graphql -F id="$(gh pr view 123 --json id -q .id)" -f query='
mutation($id: ID!) {
enqueuePullRequest(input: {pullRequestId: $id}) {
mergeQueueEntry { position state estimatedTimeToMerge }
}
}'
Remove it again
dequeuePullRequest (“Remove a pull request from the merge queue”) takes the pull request’s id and returns the dequeued mergeQueueEntry. GitHub’s docs list “a removal via the API or merge queue interface” among the reasons a pull request leaves the queue; a failing check on its merge group removes it too.
mutation($id: ID!) {
dequeuePullRequest(input: {id: $id}) { mergeQueueEntry { state } }
}
Read the queue
repository.mergeQueue(branch:) returns the queue for that branch (the default branch if you leave it out). Its entries are paginated; each entry has position, state, enqueuedAt, enqueuer, estimatedTimeToMerge (seconds), jump, solo, baseCommit, headCommit and its pullRequest. The queue also has nextEntryEstimatedTimeToMerge and its configuration (merge method, build and merge limits, check timeout).
query {
repository(owner: "your-org", name: "your-repo") {
mergeQueue(branch: "main") {
nextEntryEstimatedTimeToMerge
entries(first: 20) {
totalCount
nodes { position state enqueuedAt pullRequest { number title } }
}
}
}
}
An entry’s state is one of QUEUED, AWAITING_CHECKS, MERGEABLE, UNMERGEABLE or LOCKED.
The merge_group event for CI
The queue tests each pull request on a temporary branch with the latest base branch and the pull requests ahead of it. GitHub’s docs: “You must use the merge_group event to trigger your GitHub Actions workflow when a pull request is added to a merge queue”; without it, required checks never report and the queue waits.
on:
pull_request:
merge_group:
- Webhooks: the
merge_groupwebhook is available to GitHub Apps (they need at least read access to the “Merge queues” repository permission) and has the actionschecks_requested(run your checks on the group’s head commit) anddestroyed, with areason: merged, dequeued, or invalidated by an earlier entry leaving the queue. GitHub suggests cancelling checks still running for a destroyed group. - Other CI providers: run on pushes to branches starting with
gh-readonly-queue/{base_branch}, the prefix of the queue’s temporary branches.
Private repos on GitHub Team
All of the above works only where GitHub offers the merge queue. For private repositories on GitHub.com that means GitHub Enterprise Cloud; on GitHub Team the “Require merge queue” option isn’t available for a private repo. The options and what each costs are in Can you use GitHub’s merge queue on the Team plan?
Queue to Main is one of those options: a GitHub App that queues and merges pull requests on any plan, at a flat price per organization rather than per seat (see pricing). It doesn’t use the API above, which only drives GitHub’s own queue; you queue a pull request by adding the label queue or commenting /queue, and your CI runs on its fmq/** test branches (see Setup).
Sources
All read 2026-11-17 on docs.github.com (GitHub.com, Free/Pro/Team version).
- REST API endpoints for pull requests: “Merge a pull request asynchronously” (
merge-async,merge_action, responses), “Get the result of an asynchronous merge”, and the note on the older merge endpoint - REST API endpoints for rules: the
merge_queuerule type. A search of GitHub’s docs for “dequeue” on 2026-11-17 returned only the GraphQL reference. - GraphQL reference: Pull requests:
enqueuePullRequest,dequeuePullRequest,MergeQueue,MergeQueueEntry,MergeQueueEntryState,MergeQueueConfiguration, and the pull request fieldsisInMergeQueueandisMergeQueueEnabled - GraphQL reference: Repositories:
Repository.mergeQueue(branch:) - Managing a merge queue: who can queue, the
merge_grouptrigger, temporary branches, reasons for removal - Webhook events and payloads: merge_group:
checks_requestedanddestroyed
GitHub’s API changes; check the linked reference before you build on it. Not affiliated with GitHub. GitHub is a trademark of GitHub, Inc.