Skip to article

Stacked pull requests

How Merget queues, prepares and lands pull requests that are built on top of other pull requests.

On this page

A stacked pull request is one whose base branch is the head branch of another open pull request, instead of the target branch. Merget follows stacks on its own: you don't need a stacking tool, a label or a command, and a stack made with GitHub's own stacking is followed the same way. This page covers what is different for stacks. For the general queue rules, see The merge queue; for the queues a stack can fold into, see Branch queues.

How stacks join the queue

A stacked pull request joins the queue when:

  • it is open and not a draft;

  • its parent is in the queue.

The pull request at the bottom of the stack, the one that targets the target branch, is the stack's root. Merget follows a stack to any depth.

If the parent is closed or converted to a draft, the parent leaves the queue and takes its whole sub-stack with it. The queue's Drafts tray groups a draft parent with the children waiting for it. Open it to see which parent must become ready for review; see Pull requests outside the queue.

For example, in acme/payments, #241 "Rename billing formatter" targets main. If #242 "Add checkout totals" is opened with #241's branch as its base, #242 is stacked on #241, and #241 is the root.

A repository can turn this inference off: with stack inference off (stacks.infer_from_bases), a pull request whose base is another pull request's branch is in no queue, listed under Not in a queue with the reason Stack inference is off for this repository, until you make it a GitHub stack, retarget it, or turn the setting back on. Stacks made with GitHub's stacking are followed either way. See Queue behavior.

A GitHub stack whose base is another pull request's branch is the exception: GitHub merges a stack into its own base and never moves a layer's base, so no queue can land it into the target branch. Its layers wait under Not in a queue, with the reason that they are a layer of that GitHub stack, which GitHub lands into the other pull request's branch, until the stack's base is a branch Merget queues. The pull request that owns that branch is queued and lands on its own. To land the stack, land that pull request first and move the stack's base on GitHub, or merge the stack by hand.

Branches that don't count as stacks

Pull requests that target these branches are not stacked:

  • The target branch or the repository's default branch, in any mode.

  • A branch that has a queue of its own. Another landing branch of the repository, a protected integration branch that an open pull request merges into the target, and the branch of a stack root set to fold each have a queue of their own; a pull request that targets one of them joins that queue as an ordinary member, lands into that branch, and is never retargeted. See Branch queues.

  • Another protected branch with no queue, in Queue and Autonomous mode. Pull requests that target a branch with a classic protection rule, or with a ruleset that requires pull requests, requires status checks or uses a merge queue, are left out of the queue while no queue lands into that branch. The same applies while Merget can't read that branch's protection.

Note

An unprotected long-lived branch that is itself the head of an open pull request, with no queue of its own, turns every pull request that targets it into a stacked pull request: if a pull request merges develop into main, every pull request that targets develop joins the main queue as stacked, and Merget retargets them to main when the develop pull request merges. To land them into develop first instead, set that stack to fold, which gives develop a nested queue of its own; see Landing style. A private repository whose GitHub plan offers neither branch protection nor rulesets (GitHub Free, or a private fork of a repository on it) can't protect its branches, so Merget reads them all as unprotected: there, the fold is the one way to give such a branch a queue of its own. In Advisory mode Merget still shows such pull requests as stacked, but it never retargets them.

How stacks are ordered

A stacked pull request is placed after its parent. Expand Queue position & history in its details to read the placement reason.

A child that joins the queue while a batch already carries pull requests queued behind its parent is placed behind the work already in progress instead: right behind its parent, it would come ahead of those pull requests, and their batch would then be tested again. Queue position & history explains the placement. It is prepared on top of what is queued ahead of it, those pull requests included, and can join a batch behind them; it still lands after its parent, as described in Landing with the parent.

When a parent has several children, each child is followed by its own sub-stack. A child can therefore appear several rows after its parent, with another branch of the same stack in between.

Being stacked is not reported as an interaction between parent and child. Findings on a child are about the child's own changes.

Before merge, root PR 241 targets main and child PR 242 targets PR 241’s branch. After PR 241 merges, Queue and Autonomous modes retarget PR 242 to main. Follow the child’s updated readiness and checks before merging. Set to fold, the children land into PR 241’s branch first through a nested queue, and PR 241 then lands into main with them.

Illustration: this stack variant uses the billing and checkout pull requests to show parent-first landing and retargeting, and the same stack set to fold.

What to look for
  • A child joins the queue when its base is a queued parent’s branch. It is ordered after its parent.
  • In Queue and Autonomous modes, merging a parent retargets its child one level toward the target branch. Follow the child’s updated readiness and checks before merging.
  • An eligible child behind its parent in the ready sequence can join its parent’s batch or a batch behind it; see the stack guide’s landing requirements. Otherwise it lands after its parent. Advisory mode does not retarget branches.
  • A hand-chained stack set to fold lands the other way round: its children merge into the root’s branch first, through a nested queue of that branch, and the root then lands into the target branch carrying all of them.

How stacks look in the dashboard

  • Merge order: stack headings and indentation keep parents and children recognizable. Each pull request's number, author, readiness and other detail lines align beneath its own title; dividers mark the row boundaries. Each row retains its actual queue position, including when another child or branch of the stack lands between them. Read the position badge for landing order and the indentation for the parent-child relationship.

  • Git tree: commit ancestry shows where branches diverge, with queue positions and readiness on pull request heads. Use Merge order for the planned landing order.

  • Relationships: stack boxes and solid links connect parents and children. A stack can also share code interactions with other changes.

  • Details: Related pull requests names parent and child connections; Queue position & history explains the order and whether the child can land with its parent.

A stack set to fold looks different: its root is an ordinary row of the target branch's queue, and its children are listed under that row as the root's nested queue. See Landing style.

See Repository queue.

A repository queue with its ranked pull requests on the left and the PR Relationships map on the right.

Read merge order from the list; use the map to inspect relationships.

What to look for
  • Position is shown beside every pull request. Readiness appears beneath its title.
  • Switch the left pane between Merge order and Git tree. Select a pull request to open its details.

Waiting for the parent

A child waits while its parent has conflicts that are not resolved yet. It is prepared once its parent is.

A child also never lands before its parent. It can merge only once its base is the target branch: Merget retargets it after the parent merges, or, when the two land together, right before that landing.

On GitHub, the child's Merget check has the Action required result while it waits. Its summary says it is stacked on the parent, that the parent merges first, and that the child is then retargeted to the target branch. A child placed behind the work in progress also reads why it isn't right behind its parent. When the child is in the same batch as its parent, the summary says instead that it lands in this batch together with its parent. When it is in a batch behind its parent's, the summary says that its parent lands ahead of that batch and that Merget retargets the child before it lands; in Queue mode it also says when you may merge it by hand.

When the parent merges

In Queue and Autonomous mode, when a parent merges, Merget changes the child's base branch on GitHub to the branch the parent merged into. It moves one level per merge: the next child is retargeted when its own parent merges. Merget only retargets pull requests that were in the queue as stacked, or that were in the nested queue of a root set to fold when the root merged first.

After the retarget, the child is a normal queued pull request targeting the target branch. It keeps waiting for the changes ahead of it and must satisfy the current preparation, check and review requirements. If GitHub refuses the base change, the queue explains what needs attention.

In Advisory mode Merget changes no pull requests, so it doesn't retarget. After the parent merges, change the child's base branch to the target branch yourself. GitHub also retargets such pull requests when the parent's branch is deleted after the merge. See GitHub's guide to changing the base branch of a pull request.

Landing with the parent

A child doesn't have to wait for its parent to merge before it can land. When the parent is in the ready sequence, the child behind it can read Ready in sequence too, and with batching on it joins the same batch as its parent. A whole stack can therefore be tested together and land at once, whatever its depth, unless you set a batch size. A second child of the same parent, which comes after the first child's own sub-stack, joins the sequence the same way: it is prepared on top of what is planned to land ahead of it.

If the parent's batch is already formed or full, the child can be tested in a later batch. It still lands after the parent. A child may need to wait when a resolution held with the queued combination prevents it from joining a batch yet; its details explain the dependency. See Where each resolution goes and Several batches in CI at once.

Merget retargets such a child to the target branch itself, right before it lands:

  • Queue mode, with Merge this sequence: Merget retargets every stacked pull request in the batch, parents first, right before the push that lands the batch. GitHub then marks each of them merged. If the push is refused, Merget moves the base branches back.

  • Autonomous mode: with Merge API landing, Merget retargets each child right before its own merge, once its parent has merged. With Fast-forward push landing, it retargets them right before the push, as in Queue mode. See Landing options.

Each pull request of the stack lands as its own commit, a merge commit unless the repository's merge method says otherwise, so the history keeps one entry per pull request. See How a batch lands.

A child whose parent isn't in the ready sequence waits for its parent to merge and lands on its own, as described above. When you merge a sequence by hand in Queue mode, Merget retargets each child after its parent merges.

Merge this stack, in Queue mode, lands a stack's ready layers up to the pull request you choose under one request: the layers below it and everything the queue orders ahead of them, the same sequence Merge this sequence would land. It is not offered on the root of a stack set to fold, whose children land through the nested queue instead.

For a GitHub stack, while native landing is on for the repository, Merge this stack lands the ready layers as one batch through GitHub's stack merge, which GitHub merges in one merge commit, the topmost layer's; pull requests ordered ahead of the stack land first, by one push, in a batch of their own, under the same request. In Queue mode a GitHub stack's layers and other pull requests are never in one batch. When a batch already holds lower layers of the stack, the layers above it are not offered until that batch has landed: GitHub's stack merge rebases them onto the target branch, so Merget certifies them again and they land in the next batch. While native landing is off, Merget lands no GitHub stack: its layers read Waiting — native landing is off (see Readiness labels) and wait behind every pull request that can land, and you merge the stack on GitHub.

Land it now is not offered for a GitHub stack: GitHub merges its layers itself. While native landing is on, Merget lands it once GitHub reads it mergeable; otherwise, merge it on GitHub. Nor is Merge anyway: no push of Merget's lands a GitHub stack's layers over failing checks, so fix the failing check, or merge the stack on GitHub. When GitHub refuses the stack merge of a stack you asked Merget to land, that request ends; the batch waits, and Merget asks GitHub again once GitHub's reading of a layer changes.

Landing style

A stack Merget inferred from base branches lands in one of two styles:

  • Through, the default: each pull request lands onto the target branch as its parent merges, retargeted one level per merge, as the sections above describe.

  • Fold: the children land into the root's branch first, through a nested queue of that branch, and the root then lands into the target branch as an ordinary pull request of the target's queue, carrying all of them. The children are members of the nested queue, not stacked pull requests: they are ordered and prepared against the root's branch, land into it by that queue's own Merge N PRs into … request, and are never retargeted while the root is open. The root's check reads "Lands into main; the queue of feature (2 PRs) lands into it first." — what is live, not an order Merget enforces: you can merge the root first, and its remaining children are then retargeted to the target branch and queued there.

The repository's default landing style (stacks.default_landing, under Queue behavior) applies to every inferred stack. An agent sets the style of one stack with the set_landing action of merget_queue_action, naming the root or the nested queue's branch (see Operate Merget); the API route is PUT …/queue/stacks/{number}/landing. Setting a stack to through again retires its nested queue: its pull requests return to the target branch's queue on the next pass, and a repository default of fold does not open it again for that root. A change is recorded on the queue's timeline as "Landing set to fold (was through)".

What can't be set:

  • A GitHub stack lands as GitHub lands it (through Merget's request, or on GitHub where Merget has turned native landing off for the repository): through GitHub's stack merge, in a batch of its own. A GitHub stack Merget cannot land as it stands waits at the back of the queue, and says why, so the pull requests behind it are not held up.

  • A protected integration branch has a queue of its own already, and keeps it.

  • A root that is itself in a nested queue: queues nest one level.

  • A branch that Excluded branches match, or that Only these branches leaves out.

  • While a landing carries the root or one of its children: wait for it to finish.

See Stacks that fold for how the nested queue lands, and Look-through for what Merget reads across the two queues.

Preparation and fixes

In Queue and Autonomous mode, each pull request in a stack is prepared on its own:

  • While the parent is queued, Merget pushes nothing to the child's branch. Fixes the child needs stay with the queue's combined result and land together with the stack. If the parent lands on its own first, the child is retargeted and prepared like any other pull request, and Merget may then push to its branch. See Where each resolution goes.

  • A stacked pull request is not verified through your CI before its parent lands; it proceeds marked not verified. See Verification through your CI.

  • Merget may push to the parent's branch while the stack is queued, and to a child's branch only after its parent has landed, so pull before you push to a branch Merget has pushed to.

To prepare one pull request of a stack again, use Retry preparation. See Retry preparation.

Merge method

Stacks work best with merge commits. In Autonomous mode, Merget merges with the repository's Merge method setting: with Default, a merge commit when the repository allows merge commits, doesn't require a linear history and has no ruleset on the target branch that leaves merge commits out, otherwise a squash merge, if the repository allows one; or the merge commit, squash or rebase you chose. See Choosing the merge method and Merging.

A squash or a rebase rewrites the parent's commits, so a child can land together with its parent only when the landing keeps the tested commits:

  • Autonomous mode: a child lands together with its parent only when Merget merges with merge commits. When Merget would squash or rebase, whether you chose that or Default falls to a squash, the child lands after its parent, one at a time.

  • Queue mode: Merge this sequence lands a stack exactly as tested, whatever the merge method. But when the repository doesn't offer merge commits and the target branch also refuses Merget's push (see Prerequisites for fast-forward landing; a required linear history does both), a child lands after its parent, one at a time.

If you merge by hand in Queue or Advisory mode, prefer Create a merge commit for pull requests that have children. A stack set to fold is not affected: its children land into the root's branch by fast-forward, and the root lands as one pull request.

Limits and caveats

  • There is no limit to how deep a stack can be.

  • A stacked pull request reads Ready in sequence, and joins a batch, only behind its own parent in that sequence: in its parent's batch, or in a batch behind it. In Autonomous mode it does so only when Merget merges with merge commits; in Queue mode, only when the repository offers merge commits or the target branch lets Merget push. See Merge method and Landing with the parent.

  • A child waits while its parent has unresolved conflicts.

  • Closing a parent or converting it to a draft takes its whole sub-stack out of the queue.

  • Merget retargets children only in Queue and Autonomous mode.

  • The children of a stack set to fold are not stacked pull requests: the rules above about waiting for the parent, landing with it and retargeting don't apply to them while the root is open. See Landing style.