Skip to content
Source
Sign inSign up

Review and merge a stack

Issues and pull requests / Stacks and private work

Review and merge a stack of pull requests

An agent split a big change into several pull requests, each one on the one before it. You want to review them in order, then merge them all, with no rebase and no fix of base branches by hand.

7 min read

The forge shows these pull requests as one stack. A push to one of them is merged into each one above it. One merge button lands the stack from the bottom.

To make a stack yourself, see Split a change into a stack.

1. Find the stack

  1. Open the repository, then Pull requests.
  2. Find the row with a Stack of 3 button and the numbers of the stack, for example #101 to #103. The list groups a stack from the pull requests of the same page (25 for each page). If you do not see all of the stack, scroll down: the next page loads near the end of the list.
  3. Read the pull requests of the stack below that line, bottom first. Each one has the row that the list shows for any pull request, with its labels and CI, and a line joins its icon to the stack icon. A pull request of the stack on another page shows only its number and title. Click Stack of 3 to fold them away.
The Pull requests list with a Stack of 2 row: its line #6 to #7, CI passed on 1, and below it the rows of pull requests #6 and #7 at the full width of the list, each with its badges and author, joined to the stack icon by a line through their icons

The first line of the row sums up the stack, for example CI passed on 3, 1 draft. See Stacks show as one row.

2. Review the pull requests in order

  1. Open the bottom pull request.
  2. On the Conversation tab, read the Stack: 1 of 3 panel. It is at the top of the Status tab of the right column, above the merge box.
  3. Review the pull request.
  4. In the panel, click the next pull request, and review it.
The stack panel of pull request #2: Stack: 2 of 2 with a Break stack button, and a line that joins #2, a link icon, #1 and main at the bottom

The panel lists the stack, top first, on a line that joins the pull requests:

  • The line ends at the branch that the bottom pull request merges into, for example main.
  • A link icon sits between each pull request and the one below it.
  • The line is dashed where a link is cut.
  • This pull request has a filled dot and a shaded row.

On a phone, the right column is under the description, above the timeline.

The base branch of each pull request is the head branch of the one below it. So each diff shows only the change of that pull request.

3. Ask for a change in any pull request

Ask for the change in a review, as on any pull request. The author pushes the fix to that pull request. Then the forge merges it up the stack:

  • It merges the new head into the pull request above, then that one into the next, to the top.
  • Each step is a merge commit by the bot, with a message such as Merge #101 into #102 (stack sync).
  • No branch is rebased, and nothing is force-pushed. git pull keeps working on each branch.
  • CI runs on each head that moves.
  • The steps go through a queue, so the pull requests above take a moment to update.

If a sync step conflicts

The forge stops the sync at that pull request:

  • Its row in the stack panel shows Stack needs update: conflict with #101.
  • The stack row of the list says 1 needs an update.
  • The author merges the lower branch in and pushes. See Fix a sync conflict.
  • If the factory step Resolve merge conflicts is on, it gets a run on that pull request. Its agent, Keep green, is off by default.

4. Merge the stack

  1. Open the highest pull request that you want to land. For the whole stack, open the top one.
  2. Read the merge button. It names each pull request that lands, and the base branch, for example Merge #101, #102, #103 into main.
  3. Pick Create a merge commit, Squash and merge or Rebase and merge in the menu beside the button.
  4. Click the button, then click Confirm merge (or Confirm squash and merge, Confirm rebase and merge).
The merge box of pull request #2, with the button Merge #1, #2 into main and the Create a merge commit menu

The forge merges the pull requests from the bottom, each as its own commit, with the method that you picked:

  • The title and the message that you type are for the pull request that you opened. Each one below it gets its default text.
  • After each merge, the pull request above it gets the merged base (for example main) as its new base.
  • The pull requests above the one that you opened stay open. The forge merges the new base into the next one, once.
  • Not ready lists the pull requests below that are a draft, or that have a sync conflict.

If one pull request cannot merge, the merge stops there:

  • The ones before it stay merged.
  • The box says what happened, for example Merged #101. #102 did not merge: ....
  • The forge merges the new base into the pull request that did not merge, once.

In a terminal:

src pr merge 103 --squash

src prints one line for each pull request that landed, bottom first.

Note

Each merge has the usual rules. You need write access, and the branch rules of the base branch apply. A draft cannot merge. An agent never merges into the default branch: a person merges.

Merge when ready on a pull request of a stack waits until the pull requests below it have merged. Then it merges into their base.

After each merge, the forge deletes the head branch of the pull request that merged, unless the repository keeps head branches. A branch that is the head or the base of another open pull request stays. See Delete head branches after a merge.

Done

You found the stack as one row, and reviewed its pull requests in order. Fixes in any pull request reached the ones above it with no force push. One merge landed the stack in main, from the bottom, each pull request as its own commit.

Later: stop the sync between two pull requests

You want #102 to stay as it is while #101 changes. Unlink #102 from #101.

  1. Open #102.
  2. In the stack panel, move the pointer to the link icon between #102 and #101.
  3. Click Unlink.
The stack panel of pull request #2 after the unlink: #2 at the top, and a dashed line down to On #1 (unlinked) with a Link again button

What happens:

  • No branch moves. #102 keeps the head branch of #101 as its base.
  • The stack splits in two. The upper part shows On #101 (unlinked) in the panel, and on #101 (unlinked) in the list.
  • #102 cannot merge while #101 is open. Its merge button reads Waits for #101.
  • When #101 lands, #102 gets the base of #101 (for example main) as its base. The forge merges that base into #102 once.
  • The timeline of #102 shows unlinked this pull request from the one below it, and later changed the base branch from ... to main. It does not name the lower pull request, because some readers of #102 cannot read it.

To sync again, click Link again in the panel of #102. The forge merges the head of #101 into #102 at once.

To unlink every link of the stack, click Break stack. Each pull request keeps its base.

  • The author of the upper pull request can unlink and link again. So can people with write access.
  • These changes need a connection. The page waits for the server, then shows the new stack.