Skip to content
Versora

Manual

Stacks

Pushing the stack

5 min read

On this page

After a restack, several branches changed at once, and the ones that were already on the server need a force push. Pushing them one by one is slow and risky: if the third push fails, the server is left with half of the new stack. Push the stack does a single push for all the branches that changed, with a single confirmation. Either everything goes, or nothing does.

Where to find it

  • STACKS section: push button in the stack header (tooltip: "Push the stack (some branches aren't on the remote)"). It only appears when there's something to push.
  • Branch menu › Branch stack › Push the stack… (disabled when everything is already on the remote).
  • Stack header: right-click › Push the stack…
  • Palette (Ctrl+P): "Push the stack…" (detail: "Push each branch with --force-with-lease, with one confirmation").
  • Push the stack button in the end notices of other operations: restack, sync, reorder, fold and update from the server.

Step by step

  1. Open Push the stack… from any branch of the stack.
  2. Versora picks the remote: the one from the GitLab or GitHub integration; otherwise origin; otherwise the first remote.
  3. It runs the push checks for each branch, without opening their own dialogs.
  4. Check the Push feature/a? dialog:
    • "3 branches go to origin in a single push (atomic: all or nothing):";
    • one line per branch, with what will happen (table below);
    • the note "With --force-with-lease, if someone pushed after your last fetch, the server refuses instead of wiping out their work.";
    • if a branch still needs a rebase: "Heads up: some branches need a restack (their parent moved). Consider restacking first.";
    • if the checks found something: "The push checks found:" and the list, with the branch name before each finding (for example, "feature/b · Secrets: …").
  5. Click the confirmation button. Its text changes depending on the case:
    • Push the stack: only new or fast-forward branches;
    • Force push the stack: a branch was rewritten;
    • Push anyway: the checks found something.
  6. The bar shows "Pushing 3 stack branches…". At the end: "3 stack branches pushed to origin." The merge request list is read again.

What each line of the plan says

LineMeaning
"feature/c → origin/feature/c (new on the remote)"The branch doesn't exist on the server yet. It's created and gets an upstream.
"feature/a → origin/feature/a (fast-forward; the remote must be at 1a2b3c4)"The branch only gained commits. The push is an ordinary one, but the remote must be at the given commit.
"feature/b → origin/feature/b (force push; the remote must be at 5d6e7f8)"The branch was rewritten (rebase, amend). The push replaces what's on the server, only if it's still at the given commit.

What Versora does in git

A single command, with one protection per branch:

bash
git push --atomic \
  --force-with-lease=refs/heads/feature/a:1a2b3c4… \
  --force-with-lease=refs/heads/feature/b:5d6e7f8… \
  --force-with-lease=refs/heads/feature/c: \
  origin \
  refs/heads/feature/a:refs/heads/feature/a \
  refs/heads/feature/b:refs/heads/feature/b \
  refs/heads/feature/c:refs/heads/feature/c
  • --atomic: the server accepts all the branches or none. If the server doesn't support atomic push, Versora repeats the same command without --atomic.
  • --force-with-lease=<ref>:<commit>: the expected commit is the one the screen showed. If someone pushed after your last fetch, the server refuses instead of wiping out their work. For a new branch, the expected value is "none": if someone created the branch in the meantime, the push is refused.
  • The branches that didn't have an upstream yet start tracking the created remote branch (git branch --set-upstream-to=origin/feature/c feature/c).

The extra check: commits you haven't brought in yet

--force-with-lease compares with what your repository knows about the server. A fetch, including the automatic one, may have brought a teammate's new commits to origin/feature/b without them having gone through your feature/b. In that case the lease wouldn't protect you: it already sees the new commit as "expected".

That's why, before the push, Versora checks whether the server version of each branch was already integrated into your local branch. It's the same rule as git push --force-if-includes, which git ignores when the lease carries the explicit commit. If it wasn't, nothing is pushed and you see:

"Push refused before sending anything: the server has commits on feature/b that you haven't brought into the local branch yet (a fetch downloaded them, but they never went through the branch). A force push would erase them. Use "Update the stack from the server" (or pull) and push again."

The notice has the Update the stack from the server button, which brings those commits into the stack's branches (see Updating the stack from the server). Then push again.

Push checks

The same checks as an ordinary push run for each branch of the stack: secrets, protected branch, push rules and CI validation (see Checks). In the stack, they don't open their own dialogs: the findings go into the single confirmation, and the button becomes Push anyway. A serious finding turns the button red.

How to undo

The push doesn't go into Ctrl+Z: it changes the server, not your local branches. To bring the server back to an earlier version, bring the local branches back (for example, with the Ctrl+Z of the operation that rewrote them) and push the stack again.

Caveats and messages

  • "The stack is already on origin: nothing to push.": all the branches match the server.
  • "The repository has no remote to push the stack to.": add a remote (see Remotes).
  • "feature/b isn't part of a stack.": open the action from a branch of the stack.
  • "The stack push was rejected: …": the server refused the whole atomic push. Read the reason (a lease that didn't match, a protected branch, a push rule) and fix it before pushing again.
  • Lease rejection ("stale info" in the git output): someone pushed after your fetch. Use Update the stack from the server and push again.

Caution

A force push rewrites the branch for everyone. In a stack this is expected (each restack changes the commits), but coordinate with whoever else works on the same branches.

  • The checks follow Preferences › Checks, Preferences › Push rules and Preferences › CI validation.
  • The company policy applies as in an ordinary push: allowed_servers, secrets_scan and protected_branches (see Administrators).
  • The stack push doesn't offer "Don't ask again" like the ordinary force push: the stack confirmation always appears.

See also