git-stash-pop-pulls-unrelated-stashlisted
Install: claude install-skill wan-huiyan/agent-traffic-control
# `git stash pop` pulls an unrelated stash when preceding `git stash` was a no-op
## Problem
You defensively wrap a risky operation with `git stash` / ... / `git stash pop`
to preserve in-progress work. The working tree is clean, so `git stash` prints
**"No local changes to save"** and exits 0. Later, `git stash pop` pulls in
modifications from a *different* branch's stash entry — sometimes months old,
sometimes from another worktree, often producing merge conflicts in files you
never touched in this session.
## Context / Trigger Conditions
You'll see one or more of:
- `git stash` immediately echoed **"No local changes to save"**
- `git stash pop` runs without error and announces something like
`On branch <X>: WIP on <other-branch>: <sha> <commit-msg-from-elsewhere>`
- `git status` afterward shows:
- Modified or unmerged files you didn't touch
- `both modified: <path>` for paths from unrelated features
- Filenames matching files on entirely different branches
- `git stash list` shows entries like `stash@{0}: WIP on feature/sca-polish: ...`
that reference branches you're not on
## Root Cause
The stash stack is a **global, branch-agnostic, LIFO data structure**, shared
across every worktree of the repo. `git stash pop` always pops `stash@{0}` —
it doesn't care which branch the stash was created on. When `git stash` is a
no-op (clean tree), nothing is pushed onto the stack, so a subsequent
`git stash pop` reaches whatever was on top *before* this session — poten