Repository navigation
Description
Describe the bug
gh stack sync fails when a PR has been added to the stack on GitHub (via the web UI) and its head branch already exists locally. Instead of adopting the existing local branch into the local stack, sync aborts:
✗ Cannot pull feature-3 from the remote stack: a local branch with that name already exists
This happens even when the local branch is identical to its remote-tracking branch (0 0 ahead/behind). Because sync aborts at this step, nothing else is synced, so the local stack can't catch up with the remote stack.
Affected command
gh stack sync
gh-stack version
gh stack version 0.3.0
GitHub CLI version
gh version 2.104.0 (2026-11-12)
Operating system
Windows 11
Shell
PowerShell 7
Steps to reproduce
- Create a stack locally with
gh stack init feature-1 feature-2and submit it. - Without using gh stack, create
feature-3on top offeature-2, push it, and open a PR based onfeature-2. - In the GitHub web UI, add the
feature-3PR to the stack. - Run
gh stack syncin the original clone, wherefeature-3exists locally and matchesorigin/feature-3.
Expected behavior
Sync sees that the local feature-3 is the PR's head branch and adopts it into the local stack. It could do that automatically when the local branch matches the remote one or is an ancestor of it, or prompt when they differ. Then it carries on syncing.
Actual behavior
Sync aborts with "a local branch with that name already exists" and the local stack metadata isn't updated.
Workaround: rename the local branch out of the way so sync can recreate it from the remote, then delete the renamed copy:
git branch -m feature-3 feature-3-presync
gh stack sync
git branch -D feature-3-presync
This only works because the local and remote branches were identical. Any local-only commits would have to be reapplied by hand.
Terminal output
> gh stack sync
✗ Cannot pull feature-3 from the remote stack: a local branch with that name already exists
Preflight checks
- I searched the existing issues for duplicates.
- I ran
gh extension upgrade stackand reproduced this issue on the latest stable release.
Activity