Skip to content

[Bug]: gh stack sync won't adopt an existing local branch #641

Backlog

Description

@adaviding

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

  1. Create a stack locally with gh stack init feature-1 feature-2 and submit it.
  2. Without using gh stack, create feature-3 on top of feature-2, push it, and open a PR based on feature-2.
  3. In the GitHub web UI, add the feature-3 PR to the stack.
  4. Run gh stack sync in the original clone, where feature-3 exists locally and matches origin/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 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

    bugBug Reports

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions