Queue to Main

Guide · GitHub API · facts checked 2026-11-17

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

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)"

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:

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).

GitHub’s API changes; check the linked reference before you build on it. Not affiliated with GitHub. GitHub is a trademark of GitHub, Inc.