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

rebase/sync fail when an unrelated branch is checked out in two worktrees

Open schickling-assistant opened this issue 4 weeks ago • 0 comments

Problem

gh stack rebase (and sync, modify) fails when any branch in the repository is checked out in two worktrees, even a branch that is not part of the stack:

branch <other> is checked out in multiple worktrees (<path-a> and <path-b>)

In a clone with many worktrees, one stray duplicate checkout of an unrelated branch blocks every stack operation in every worktree until someone else's worktree is fixed.

Cause

worktree.New() builds the branch → worktree map from all worktrees and returns an error on the first duplicate it sees (https://github.com/github/gh-stack/blob/2a49e6751238633db504655d8a8eba3e433e827d/internal/worktree/context.go#L32-L54). This runs before Preflight, which is the step that knows which branches the operation will touch (https://github.com/github/gh-stack/blob/2a49e6751238633db504655d8a8eba3e433e827d/internal/worktree/context.go#L202-L210).

Expected

Record duplicates in New() instead of failing, and reject them only in Preflight/Ops for branches the operation actually touches. The ambiguity check stays for stack branches; unrelated branches no longer block the command.

Repro

  1. In a clone with a stack a → b, check out an unrelated branch x in two worktrees (git worktree add --force).
  2. Run gh stack rebase in the stack worktree.
  3. It fails with "branch x is checked out in multiple worktrees", although x is not in the stack.

This issue was drafted with AI assistance.

Posted on behalf of @schickling
field value
agent_identity agent/dotfiles/upstream-manager
session 01a10cc8
agent_persona generalist
agent_supervisor unavailable
agent_tool OMP
agent_tool_version 18.10.2
agent_runtime OMP 18.10.2
agent_model anthropic/claude-opus-5-5
worktree unknown

schickling-assistant avatar Nov 02 '26 14:11 schickling-assistant