git-stash-pop-pulls-unrelated-stash

Diagnose and prevent git stash pop from applying unrelated stashes after a no-op stash.

3|Updated May 8, 2026
One-click install
npx skills add https://github.com/wan-huiyan/agent-traffic-control --skill git-stash-pop-pulls-unrelated-stash-wan-huiyan
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-stash-pop-pulls-unrelated-stash
Source: https://github.com/wan-huiyan/agent-traffic-control/tree/main/plugins/agent-traffic-control/skills/git-stash-pop-pulls-unrelated-stash
Command: npx skills add https://github.com/wan-huiyan/agent-traffic-control --skill git-stash-pop-pulls-unrelated-stash-wan-huiyan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When you defensively wrap a risky operation with git stash / git stash pop but the working tree is clean, the stash is a no-op and the later pop pulls a stale, unrelated stash from another branch or worktree — often producing merge conflicts in files you never touched. ## Core Features & Use Cases - Root-cause diagnosis: Explains that the stash stack is global, branch-agnostic, and LIFO across all worktrees, so git stash pop always pops stash@{0} regardless of which branch created it. - Prevention patterns: Conditional pop based on stash output, mandatory -m messages for identifiable entries, pre-pop audits with git stash list and git stash show -p, and a throwaway-branch snapshot alternative. - Recovery procedure: Step-by-step cleanup using git reset HEAD, git checkout -- <file>, and verification with git status -s after an accidental pop. - Use Case: You run git stash before checking out a file from another branch, see "No local changes to save", then git stash pop later and suddenly have "both modified" conflicts in files from a months-old feature branch — this Skill walks you through safe recovery. ## Quick Start Ask the assistant to diagnose why git stash pop pulled in files from an unrelated branch and to recover the working tree to a clean state.

Frequently Asked Questions about git-stash-pop-pulls-unrelated-stash

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why did git stash pop apply changes from a different branch?▼

The stash stack is global and branch-agnostic, so git stash pop always pops stash@{0} regardless of which branch created it. If your earlier git stash was a no-op on a clean tree, the pop reaches an older stash from another branch or worktree.

How do I safely use git stash before a risky operation?▼

Check the output of git stash first: only run git stash pop if it printed "Saved working directory". Always use git stash push -m with a message so entries are identifiable, and audit with git stash list and git stash show -p before popping.

How do I recover after popping an unrelated stash?▼

Run git reset HEAD to unstage everything, then git checkout -- <file> for each file you did not intend to touch, including unmerged paths. Verify with git status -s that the tree is clean, and leave or drop the stale stash entry as appropriate.

Is the git stash stack shared between worktrees?▼

Yes, the stash stack is shared across all worktrees of a repository. A stash created in one worktree can be popped in another, so never assume your branch or worktree scopes the stash.

What is a safer alternative to git stash for saving work in progress?▼

Commit to a throwaway branch instead: create a temp branch, run git add -A and git commit, then switch back. Later cherry-pick the snapshot commit and delete the temp branch, avoiding the shared stash stack entirely.