Github stack does not persist across worktrees
When opening a branch in a worktree and running gh stack init, it does not keep track of the stack locally. gh-stack keeps stack membership in local state tied to the checkout where init ran. If I create a worktree & use gh-stack, the stack doesn't persist on my machine, even if I open the branch back in my main worktree. Inside a worktree, $GIT_DIR is .git/worktrees/worktree remove deletes the stack state with it
This is confusing & not obvious. Additionally, a modern LLM workflow may involve different sub-agents in different worktrees. This makes gh-stack worse than, say git-spice for this purpose, since I can't easily update my work if I checkout the branch on my main worktree.
The stack is stored remotely on Github, but THAT doesn't always work - seems like GitHub only records a stack for a chain of two or more PRs.
The root cause is where the stack state file is written. gh-stack stores local state at <git-dir>/gh-stack, computed via git rev-parse --git-dir. In a normal clone that is .git/gh-stack, but in a worktree it is .git/worktrees/<name>/gh-stack. That makes stack state worktree-local: it is not visible from other worktrees and disappears when the worktree is removed.
A possible fix is to store .git/gh-stack in the common git directory instead, using git rev-parse --git-common-dir. That would make the stack file repository-wide so all worktrees share the same state.
In a normal repository:
repo/.git/
gh-stack # stack state
In a worktree:
repo/.git/ # common git dir
gh-stack # shared stack state
worktrees/
wt-a/
...
gh-stack-rebase-state # can stay worktree-local
The change would be to introduce a GitCommonDir() helper, use it for the stack file path in stack.Load / stack.Save, and leave GitDir() for truly worktree-local state like the rebase state file.
This also relates to #483: once the stack file is shared across worktrees, commands that resolve a stack from an explicit target can run from any branch or worktree and see the same data.
I cannot open a PR from a fork, but I am happy to provide a patch or work with a maintainer if this direction sounds good.
Should be fixed by the merged stack ending in
- #529, I think.
Yes, this looks resolved.
I'm still having trouble using GitHub Stack vs Git-Spice because this doesn't easily support inserting into the middle of the stack (there is a modify command, but that's hard for an agent to handle b/c it's a TUI). That problem seems OOS for this issue, so feel free to close it.