Mergepatrol

How to merge stacked pull requests without breaking main

Stacked pull requests split one large change into a chain of small ones: the first targets main, the second targets the first’s branch, and so on. Reviewers get changes they can read in ten minutes. The cost lands at merge time.

Why stacks are hard to merge

Merging a stack by hand goes like this: merge the bottom pull request, retarget the next one onto main, rebase it, wait for CI, merge it, and repeat for each layer. Every step is a chance for someone else’s merge to land in between and send a layer back to CI, and every layer merged alone leaves main holding half a feature.

Two things make it worse with a merge queue that does not know about stacks:

What a stack-aware queue does instead

Mergepatrol treats a stack made with gh stack as one item in the queue:

A pull request stacked by hand, targeting another pull request’s branch without gh stack, is held: the queue cannot tell it is part of a stack.

Setting it up

  1. Make the stack with gh stack: gh stack add per layer, then gh stack submit.

  2. Install Mergepatrol on the repository and merge its setup pull request, which adds .mergepatrol/mergepatrol.yml.

  3. Get the layers reviewed as your branch requires.

  4. Label any layer mergepatrol, or from a script:

    gh pr edit <number> --add-label mergepatrol
    

    A coding agent connected to Mergepatrol’s MCP server can call queue_pull on any layer instead, which queues the stack.

To take the stack out, use the dashboard’s Queue page, or call dequeue_pull on any layer: it takes the whole stack out.

FAQ

Can a stack include a pull request from a fork? Not yet. Queue fork pull requests on their own.