Re: [RFC] stash: let the stash stack live in a configurable ref
- From
- Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
- Date
- Aug 25, 2026, 18:24 UTC
- Message-ID
- <CAB=Je-GVyfrP=3kW6hRh8aVnzkKg_6yKZW2LCV=Z1XB=T7KxFg@mail.gmail.com>
- In-Reply-To
- <xmqqecfmm76c.fsf@gitster.g>
Kristoffer Haugsbakk writes:
> To my uninformed, not-using-agents mind, what agents do with the tool > seems like the least concerning thing. They can be non-deterministically > instructed to not use the stash.
[...]
> And for determinism you can give them a git(1) wrapper that bans > git-stash(1).
A wrapper that bans git-stash(1) misses it, because a command that never mentions the stash still writes to refs/stash:
git rebase topic --autostash
Created autostash: 637ca99
Applying autostash resulted in conflicts.
Your changes are safe in the stash.
You can run "git stash pop" or "git stash drop" at any time.The entry sits in refs/stash afterwards, where every worktree sees it. rebase.autoStash lives in the shared .git/config, so one worktree can turn this on for all of them, and the flag then never appears in any command line to ban.
Having a stash subcommand and forbidding it to execute is fishy. Agents might miss the instructions and they might still attempt calling stash.
Your point about the bar for a configuration option is well taken, and so is the one about the framing. The single confused session justifies the option on its own; the agents changed how often it happens, not whether it is worth fixing.
Phillip Wood writes:
Show 5 quoted lines
> When I'm not trying to move changes between branches I associate a stash > with the branch that's checked out when it is created, not the worktree > where that the branch happens to be checked out. We already record the > branch name when creating the stash so perhaps we should add an option > to pop the last stash that was created on the current branch.
That covers more of my case than I expected. Git refuses to check the same branch out in two worktrees, so a per-branch filter separates every worktree that sits on a branch, and the entries stay visible to `git stash list`, which a private ref gives up.
The gap is a detached HEAD:
git checkout --detach
echo v2 >f && git stash push -m "my own text"
git stash list
stash@{0}: On (no branch): my own textEvery detached worktree records the same "(no branch)", so a per-branch filter groups them together rather than separating them. That is not a corner case for the tools I have in mind: one repository here has 436 linked worktrees, 23 of them on a detached HEAD, because a worktree created to look at someone else's commit has no branch to be on.
> If an agent really needs a private stash it can use "git stash create" > and record the oid of the stash under "refs/worktree/".
That is what I do today, and it works. It is also what every tool has to reimplement, and the ones that skip it produce the failure I opened with.
The two ideas may well be one knob. If the scope of the stack were configurable (the shared ref, the current branch, or a per-worktree ref), then "pop what this branch stashed" and "pop what this worktree stashed" become two values rather than two features, and a detached worktree can choose the one that still separates it.
I am happy to write the patch for whichever direction you prefer, or to test yours.
Thanks, Vladimir Sitnikov