Skip to content

[Bug]: sync can't find previous base after merged parent and remote restack leave recorded base stale #646

Backlog

Description

@saponifi3d

Describe the bug

After the bottom PRs of a stack were squash-merged, the next branch (C) was updated on the remote to sit on the squash-merge commit and the local branch was reset to the remote. The base recorded for C in .git/gh-stack was not updated and still pointed at an old tip of the merged parent B, which C no longer contains.

gh stack sync then cannot find a usable previous base for C, so it aborts before pushing anything:

  • The recorded base fails rebaseBoundaryContains because C no longer contains it.
  • The fallback, git merge-base --fork-point master C, also fails because local master was fast-forwarded past the squash-merge commit and never pointed at it, so the commit isn't in master's reflog.

The branch itself is healthy. git merge-base C origin/master returns the squash-merge commit, which is the correct cutoff. Setting base in .git/gh-stack to that commit by hand makes gh stack sync rebase and push the whole stack correctly.

This happens for us every time a bottom PR merges. The error matches #571, but the cause is different: no local rebase or worktree mix-up is involved.

Affected command

gh stack sync

gh-stack version

gh stack version 0.3.0

GitHub CLI version

gh version 2.105.0 (2026-11-17)

Operating system

macOS 26.6.2

Shell

zsh

Steps to reproduce

  1. Create a stack master <- A <- B <- C <- D … with gh stack and submit it.
  2. Squash-merge PRs A and B on GitHub. B merges as commit M.
  3. On the remote, C is force-updated to sit on M. Locally this showed up as a fetch … forced-update of origin/C, not as a push from this clone. We assume GitHub's stack feature rebased it, but we haven't confirmed that.
  4. Local C is reset to origin/C (reflog: branch: Reset to origin/C). .git/gh-stack still lists C's base as an old B tip that is not an ancestor of C.
  5. Locally master fast-forwards from a commit before M to a commit after it, so M never appears in master's reflog.
  6. Commit something on C and run gh stack sync.

Expected behavior

gh stack sync sees that C already sits on trunk past the merged PRs. It uses git merge-base C <trunk> (or the merged PR's merge commit) as the previous base, rebases C onto the current trunk, cascades upstack, and pushes.

Two ways to fix it:

  • When the parent PR is known to be merged, also accept the merged PR's merge commit as a boundary if C contains it.
  • When C is reset to its remote, update its recorded base too.

Actual behavior

Sync skips the merged branches, then aborts without rebasing or pushing any branch.

Terminal output

✓ Fetched latest master from origin
✓ Trunk master is already up to date

Rebasing stack ...
✓ Skipping A (PR #… merged)
✓ Skipping B (PR #… merged)
✗ could not determine the previous base of C after master changed; rebase this branch manually

Repro state just before the failing sync:

$ git merge-base --is-ancestor <recorded base of C> C   # false
$ git merge-base C origin/master                        # M (squash-merge commit of B's PR)
$ git reflog show master | grep <M>                     # no match

Workaround: set C's "base" in .git/gh-stack to git merge-base C origin/master, then run gh stack sync. Sync then rebased and pushed all 15 open branches with no merged commits replayed.

Preflight checks

  • I searched the existing issues for duplicates.
  • I ran gh extension upgrade stack and reproduced this issue on the latest stable release.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions