Stacks
Branch stacks (stacked merge requests)
5 min read
A big change is hard to review in a single merge request. With a stack, you split the change into
small branches, one on top of the other. Each branch has its own merge request, and each merge
request targets the branch below it, not main. The reviewer reads one part at a time, and you
keep working on the upper part while the lower one is in review.
main ← feature/a (!10 → main) ← feature/b (!11 → feature/a) ← feature/c (!12 → feature/b)
In this example:
feature/astarts frommain, and merge request!10targetsmain;feature/bstarts from the tip offeature/a, and!11targetsfeature/a, so it shows only the commits offeature/b;feature/cstarts fromfeature/b, and!12targetsfeature/b.
Versora takes care of the laborious parts of a stack:
- it redoes the rebase of all the branches at once when the lower one changes;
- it pushes them all in a single push, with
--force-with-lease; - it creates each merge request with the right target already set;
- it retargets the upper merge requests when the lower one goes into
main.
| Term | Meaning |
|---|---|
| Parent, or branch below | The branch the branch was built on. Its merge request targets the parent. |
| Branch above | The branch built on top of this one. |
| Main branch | The target of the lowest branch in the stack, usually main. The STACKS section shows "on main". |
| Base | The parent's commit the branch was last built on. It's where the branch's own commits start. |
| Restack | Redoing the rebase of each branch onto its parent's new tip. In Versora, it's "Restack". |
| Position | The branch's place in the stack, counting from the bottom: 2/3 is the second of three. |
The stack lives only in the repository's local config (.git/config). Nothing goes into the
project files or to the server. Each stacked branch gets two keys in its section:
[branch "feature/b"]
versora-parent = feature/a
versora-base = 3f9c2e1a…
versora-parent: the branch's parent.versora-base: the parent's commit where the branch's commits start. It's what lets the rebase be redone without replaying the parent's commits, even after an amend on the parent or a squash on the server.
Since the keys live in the branch.<name> section, git itself carries them along when you rename
the branch and deletes them when you delete the branch.
Tip
Since the stack doesn't leave your machine, a teammate doesn't see it through the config. They can bring the same stack from the server through the merge requests: see Getting a teammate's stack.
Besides the stacks created by Versora itself, the app reads, read-only:
| Source | How it's recognized | Tooltip on the STACKS section row |
|---|---|---|
| Versora | branch.<name>.versora-parent keys | (none: it's the default source) |
| git-town | git-town-branch.<name>.parent key | "Parent recorded by git-town." |
glab stack | files in .git/stacked/<title>/ | "glab stack." |
| Implicit | open merge requests whose target is another branch with an open merge request | "Implicit stack: the merge request targets another branch with an open merge request." |
A glab stack stack appears in the STACKS section with the title it has there. The others appear
with the name of the lowest branch.
Stacks that weren't created by Versora work for restacking, pushing and creating merge requests. Some operations, such as "Remove from the stack", only apply to recorded stacks. To save a stack from another source in Versora's config:
- Branch menu › Branch stack › Record the stack in Versora.
- Palette (Ctrl+P): "Record the stack in Versora" (detail: "Saves the implicit stack (MRs), the glab or git-town stack in the local config").
The notice "Stack recorded in the repository's local config." confirms it. After that, the stack stays valid even when the merge requests are closed. With the stack already recorded, the palette shows the command as unavailable: "the stack is already recorded".
The recording goes into Ctrl+Z as "Record the stack of feature/b": undoing it deletes from the local config the keys the recording saved (each branch's parent and base), and the stack is seen again as it was before, through its source. No branch or commit changes.
| Task | Page |
|---|---|
| Start a stack, stack a branch that already exists, remove from the stack | Creating a stack |
| Read the STACKS section and the marks in the graph | STACKS section and marks in the graph |
| Redo the rebase of all the branches after changing one of them | Restacking |
| Push all the branches in a single push | Pushing the stack |
| Create the merge requests and keep the "Stack: !10 → !11 → !12" navigation | Stack merge requests |
Carry on after the lower one went into main | Syncing the stack |
| Reorder, fold, split and view the diff | Changing the stack structure |
| Bring in what teammates pushed to the stack's branches | Updating the stack from the server |
| Build someone else's stack locally | Getting a teammate's stack |
| Merge all the merge requests, bottom to top | Merging the stack up to here |
- Git 2.38 or newer for restacking in a single rebase, with
update-ref. With an older git, the restack uses a fallback path, and the result is the same (see Restacking). In that case, the git version bar at the top of the window lists "restacking in a single rebase (2.38)" among the unavailable features (see Warnings). - GitLab or GitHub registered with a token in Git servers for everything that involves merge requests. Without a server, the stack works locally only: create, restack and push. In that case, the notice is "No GitLab or GitHub set up for this remote: the stack works locally only (create, restack and push)." See Git servers.
Preferences › Stacks has the "Navigation in the description" option and a "How it works" box,
which says whether this machine's git supports update-ref in a rebase. The palette opens the page
with "Stack preferences". There's no company policy key for stacks.