rebase/sync fail when an unrelated branch is checked out in two worktrees
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
- In a clone with a stack
a→b, check out an unrelated branchxin two worktrees (git worktree add --force). - Run
gh stack rebasein the stack worktree. - It fails with "branch x is checked out in multiple worktrees", although
xis 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 |