Skip to content
Versora

Manual

Stacks

Creating a stack

6 min read

On this page

A stack starts with an ordinary branch, for example feature/a starting from main. You create the next branch on top of it, and Versora records which branch is whose parent. There's no "create stack" command: the stack is born when the first branch gets a recorded parent.

New stacked branch

Creates a new branch from the tip of another one and records it on top of it right away. It's the most common way to build the stack, one branch at a time.

Where to find it

  • Branch menu (right-click in the left panel or on the graph label) › Branch stack › New stacked branch on feature/a…
  • STACKS section: + button in the header (tooltip: "New stacked branch on the current one"), or right-click the STACKS header › New stacked branch on feature/a…
  • A stack's header in the STACKS section: right-click › New stacked branch on feature/a…
  • Palette (Ctrl+P): "New stacked branch…" (detail: "Creates a branch from feature/a and stacks it on top").

Tip

The STACKS section only appears when the repository already has a stack. To create the first one, use the branch menu or the palette.

Step by step

  1. Check out feature/a, or open its menu.
  2. Choose New stacked branch on feature/a…
  3. In the New stacked branch dialog, read the message: "The new branch starts at the tip of feature/a and is stacked on it: its merge request will target feature/a."
  4. In Branch name, type the name (the field suggests the feature/part-2 format). For example, feature/b.
  5. Leave Check out the new branch checked to start working on it right away, or uncheck it to only create it.
  6. Click Create stacked branch.
  7. The notice "feature/b created on top of feature/a." confirms it. The STACKS section appears (or gets a new row), and the feature/b label in the graph gets the 2/2 badge.
OptionWhat it doesDefault
Branch nameName of the new branch. It must be a valid name for git and can't already exist.empty
Check out the new branchSwitches to the new branch right after creating it.checked

What Versora does in git

bash
# with "Check out the new branch" checked
git checkout --no-track -b feature/b feature/a
# without checkout
git branch --no-track feature/b feature/a

# and records the stack in the local config
git config branch.feature/b.versora-parent feature/a
git config branch.feature/b.versora-base <current tip of feature/a>

--no-track keeps the new branch from tracking its parent. That way its first push goes to a remote branch of its own, and not to the parent's branch.

How to undo

Ctrl+Z undoes "Create stacked branch feature/b": the branch is deleted and, with it, the stack keys. If there was a checkout, HEAD goes back to where it was.

Stack on…

Puts a branch that already exists on top of another one. Use it to build a stack from branches created earlier, or to change a branch's parent.

Where to find it

  • Branch menu › Branch stack › Stack feature/b on…
  • Palette: "Stack the current branch on…" (detail: "Picks the branch below feature/b").

Step by step

  1. Open Stack feature/b on…
  2. Read the message: "feature/b will sit on top of the chosen branch. History doesn't change now; if it doesn't start at the new parent's tip, the stack shows it needs a restack."
  3. In Branch below (parent), choose the parent. The list has the local branches, except the branch itself and the ones on top of it (choosing one of them would create a cycle). The current parent comes selected, if there is one; otherwise main, master or develop, in that order, if they exist.
  4. Leave Restack right after (rebase onto the new parent) checked to redo the rebase right after. Unchecked, only the record changes.
  5. Click Stack. The notice "feature/b now sits on top of feature/a." confirms it.
  6. With the restack option checked, the Restack confirmation opens next.
OptionWhat it doesDefault
Branch below (parent)The branch this one will sit on.the current parent; otherwise main, master or develop
Restack right after (rebase onto the new parent)Opens the restack right after.checked

What Versora does in git

Only the config changes, without touching any commit:

bash
git config branch.feature/b.versora-parent feature/a
git config branch.feature/b.versora-base <where the commits of feature/b start>

The base is estimated from the fork-point or the merge-base between the branch and the parent.

How to undo

Ctrl+Z undoes "Stack feature/b onto feature/a": the versora-parent and versora-base keys of feature/b go back to what they were (the previous parent, or none). Only the stack config changes; the rest of the repository config isn't touched. Ctrl+Shift+Z saves the new parent again.

If you checked the restack, the rebase that came after goes into Ctrl+Z as a separate operation: the first Ctrl+Z undoes the restack, and the second, the stacking.

Remove from the stack

Removes a branch from the stack without touching history. The branches that were on top of it now sit on its parent.

Where to find it

  • Branch menu › Branch stack › Remove feature/b from the stack (last item in the submenu).
  • Palette: "Remove the current branch from the stack" (detail: "feature/b leaves; the ones above sit on its parent").

How it works

Example: main ← feature/a ← feature/b ← feature/c. When you remove feature/b:

  • feature/b still exists, with the same commits, but with no recorded parent;
  • feature/c gets feature/a as its parent.

The notice is "feature/b left the stack; the branches above it now sit on its parent." The commits of feature/b are still in the history of feature/c. To take them out of there, use Restack afterwards.

The item only exists for branches recorded by Versora. In a glab stack, git-town or implicit stack, it doesn't appear in the menu, and the palette shows the command as unavailable ("stack not recorded by Versora"). Record the stack first, as the "Recording the stack in Versora" section of the stacks overview explains.

What Versora does in git

bash
git config branch.feature/c.versora-parent feature/a
git config --unset branch.feature/b.versora-parent
git config --unset branch.feature/b.versora-base

How to undo

Ctrl+Z undoes "Remove feature/b from the stack": feature/b gets back its previous parent and base, and feature/c sits on top of feature/b again. Later, after other operations, you can also put the branch back with Stack on….

Moving through the stack

On the current branch, you can go straight to the neighbor below or above.

Where to find it

  • Current branch menu › Branch stack › Check out the branch below or Check out the branch above.
  • Palette: "Check out the branch below in the stack" and "Check out the branch above in the stack" (the detail shows the neighbor's name).
  • STACKS section: double-clicking a row checks out that branch.
  • The item for the branch below is disabled on the lowest branch of the stack; from the palette, you see "This is the bottom branch of the stack.".
  • The item for the branch above is disabled on the top branch; from the palette, "There's no branch above this one in the stack.".
  • With more than one branch on top, "above" takes you to the first of them.
  • The checkout is the usual one, with the autostash from Preferences (see Autostash).

Caveats and messages

  • "You're on a detached HEAD: check out a branch first.": the stack actions need a checked-out branch (or a branch chosen in the menu).
  • "feature/b isn't part of a stack.": the action needs a branch that's already in a stack.
  • "There's no other local branch to stack on.": in Stack on…, there's no branch left to choose as the parent.
  • "A branch named feature/b already exists.": choose another name.
  • "Invalid branch name: …": git doesn't accept the name (spaces, .., ~, ^, : etc.).
  • "feature/b can't be stacked on itself.": the chosen parent is the branch itself.
  • "feature/c is above feature/b in the stack: stacking feature/b on it would create a cycle.": choose a parent that isn't on top of the branch.
  • "The branch feature/a doesn't exist.": the parent was deleted or renamed.

There's no preference of its own for creating stacks. The checkout follows Preferences › Operations › Autostash. There's no company policy key for stacks.

See also