git-stash
จัดการ git stash — push/pop/apply/list อย่างปลอดภัย รองรับ untracked และ named stashes
SKILL.mdgit-stash/SKILL.md
GitHubGoal
Manage uncommitted work with git stash — temporarily store changes, restore them, and clear the working tree without losing anything
Scope
- stash/push, pop, apply, list, show, drop, clear
- untracked files (
-u) and ignored files (-a) - named stashes (
git stash push -m) - does not cover permanent discard →
/git-restore; committed changes →/git-revert
Execute
1. Assess State
Goal: know what will be stashed and whether stashes are lingering
git status --short— separate staged/unstaged/untrackedgit stash list— check for old stashes not yet popped (a lingering stash = debt)- decide: short work you'll return to soon → stash; work that should be stored permanently → commit to a branch instead
2. Stash
Goal: store the changes completely and findably
git stash push -m "<meaningful message>"— always name it- untracked files need
-u; ignored files need-a(careful — includes build output) - staged only:
git stash push --staged; specific files only:-- <paths> - verify with
git statusthat the working tree is clean as intended
3. Restore
Goal: bring changes back from the right stash at the right time
git stash list+git stash show -p stash@{n}— review content before applyinggit stash apply stash@{n}— safer than pop (the stash survives a conflict)git stash poponly when confident there is no conflict — pop deletes the stash immediately after a successful apply- conflict → resolve, then
git stash drop stash@{n}yourself once the merge is done - to keep the original index state (staged vs unstaged) →
--index
4. Cleanup
Goal: do not accumulate stale stashes
git stash drop stash@{n}one by one after a successful applygit stash cleardeletes everything — must confirm and list first, always
Rules
- always
git stash push -m— no anonymous stashes (unfindable when you come back) - prefer
applyoverpop— pop deletes the stash immediately, hard to recover if the conflict goes badly - stash is not permanent storage — work pending >1 day should be committed to a branch
- untracked files are not stashed without
-u— an easy thing to forget - Use /resolve-errors if needed
Expected Outcome
- working tree clean per intent with no uncommitted work lost
- stashes are named, findable, and no stale entries accumulate