Features · Stacked branches
Stacked branches, restacked for you.
A stack is a series of branches, each built on the one below, so that a large change is reviewed as several small pull requests. The price is upkeep: every time a lower branch changes, the ones above must be rebased and pushed again. Since version 1.18, Nori remembers which branch sits on which, replays the ones above when one moves, and pushes the stack together.
What a stack is
main ← feat/api ← feat/ui ← feat/docsfeat/ui starts from feat/api instead of main, and its pull request targets feat/api. Each review then shows one step: the API, then the interface that uses it, then the documentation. You keep working on the upper branches while the lower one waits for review.
Keeping a stack up to date by hand
When feat/api gets a new commit, or is amended after review, feat/ui still sits on the old one. Each branch above has to be moved, in order:
git rebase --onto feat/api <old tip of feat/api> feat/ui
git rebase --onto feat/ui <old tip of feat/ui> feat/docs
git push --force-with-lease origin feat/ui feat/docsThe old tips matter. If feat/api was amended or squash-merged, a plain git rebase feat/api replays its former commits on top of the new ones, and you resolve conflicts with yourself.
Git 2.38 added git rebase --update-refs, which moves a linear stack in one rebase. It has three limits: it moves every branch whose tip is in the replayed range, whether or not you think of it as part of the stack; it skips a branch that another worktree has checked out; and it follows one line of commits, while a stack can hold two branches on the same parent.
Stacks in Nori
Three ways to stack a branch:
- Choose Stack on and a branch when you create one.
- Pick New stacked branch or Stack on… from a branch’s menu.
- Drop a local branch on another, in the sidebar or the graph, and choose Stack.
The sidebar gains a Stacks section. Nori stores each link in the repository’s own Git configuration, as two keys under the branch’s section:
[branch "feat/ui"]
nori-parent = feat/api
nori-base = 1e2beaf… # the commit of feat/api that feat/ui sits onBecause they live under the branch, Git keeps them in step: git branch -m renames the section and git branch -d removes it, even from a terminal. Nothing is written to refs or to a file of Nori’s own, and git config reads it all back.
Restack
An amber restack marks a branch whose recorded base is no longer its parent’s tip. Choose Restack from the branch’s menu and Nori replays that branch, then every branch above it, parents first. It asks for a clean working tree, as a rebase does. Each branch is its own rebase from the recorded base, so commits of an amended or squash-merged parent are dropped instead of replayed, and no branch outside the stack moves.
A conflict stops the restack on the branch where it happened and opens the resolver. Finish that rebase, restack again, and Nori carries on with the branches that are left. Before the first rebase, every tip the restack may move is kept, so Undo puts the moved branches back, even after a conflict.
Push the stack
Push stack publishes every branch of the stack in one git push --atomic per remote: the server takes them all or none. Each branch goes with --force-with-lease and --force-if-includes, after a confirmation, so a branch someone else pushed to in the meantime is not overwritten.
Stacked pull requests, with Pro
Stacking, restacking and pushing are free, like every Git operation in Nori. The forge side is part of Pro:
- Push & PR on a stacked branch opens its pull request on the branch below. Without Pro it targets the default branch, in the browser.
- In Reviews, a request’s Overview shows its stack, built from the requests’ branches.
- When the bottom request merges, Retarget onto main moves the next one down. Stack on… stacks an existing request, and a request’s target can be changed from its header.
Limits
- Nori writes the requests’ targets and nothing else to the forge. It does not register the stack in GitHub’s own stacked pull requests.
- Retargeting after a merge has been checked live on github.com and gitlab.com only.
- A branch of the stack checked out in another worktree blocks the restack until it is released.
- Interactive rebase does not move the branches above the one you rebase; they show Restack afterwards.
- Requests are matched to branches by name, which can be ambiguous when a fork uses the same names.
Questions people ask
What are stacked pull requests?
Pull requests that each target the branch of the one before, instead of all targeting main. A reviewer sees one step per request, and the author keeps building on top while the first is in review.
Are stacked branches free in Nori?
Yes for the Git side: stacking, Restack, Push stack and their undo. Opening each pull request on the branch below and following the stack in Reviews are part of Pro.
Does Nori use git rebase --update-refs?
No. Nori supports Git from 2.30, older than the option, and rebases each branch of the stack on its own, so only the stack’s branches move.