gh-stack icon indicating copy to clipboard operation
gh-stack copied to clipboard

Adopt equivalent server-rebased branches

Open skarim opened this issue 4 months ago • 0 comments

After a stack was rebased on GitHub, gh stack rebase and gh stack sync fetched the rewritten branch tips but would not adopt them because the local branches had diverged from their remote-tracking refs. The commands then tried to rebase or push the stale local branches, often failing even though the server-side rebase had completed successfully.

This change snapshots branch tips before fetching and adopts a server-side rewrite only when the local branch was unchanged, the remote stack is still properly ordered, and git range-diff confirms the same commits in the same order. If both sides changed, commits differ, or the history contains merges, the command stops instead of overwriting either side.

Both rebase and sync now update local branches and stack metadata directly when a safe equivalent server rewrite is detected.

Testing

  • go vet ./...
  • go test -race -count=1 ./...
  • Real-Git coverage for server-side rebase adoption through both rebase and sync
  • Coverage for local-only changes, concurrent rewrites, reordered or changed commits, merge commits, and rollback after a partial ref-update failure

Stack created with GitHub Stacks CLI • Give Feedback 💬

skarim avatar Jul 28 '26 22:07 skarim