Last Updated: May 1, 2025
Basic Stash Commands
git stashSave all tracked changes to a stash stack
git stash push -m descriptionStash with a descriptive message
git stash listList all stashed changes
git stash show -p stash@{0}Show full diff of a specific stash
git stash popApply the most recent stash AND remove it
git stash applyApply the most recent stash WITHOUT removing it
git stash drop stash@{0}Delete a specific stash entry
git stash clearRemove ALL stashes (cannot be undone)
Partial & Advanced Stashing
git stash push file1 file2Stash only specific files
git stash push -pInteractively choose hunks to stash (very useful)
git stash push --keep-indexStash working changes but keep staged changes
git stash push --include-untrackedStash untracked files too
git stash push --allStash ALL files including ignored ones
git stash branch new-branch stash@{0}Create a branch from a stash entry
git stash show --statShow summary of files changed in stash
git stash pop --indexPop stash and re-stage files that were staged
Stash Stack Management
| Item | Description |
|---|---|
stash@{0} | Most recent stash (top of stack) |
stash@{1} | Second most recent stash |
git stash list --stat | Show file summaries for all stashes |
git stash drop stash@{0} | Remove the top stash after applying |
git stash pop stash@{1} | Pop a specific stash (not just the top) |
git stash store -m msg sha | Manually insert a commit into stash stack |
git stash show stash@{1} | Inspect an older stash without applying |
stash reordering | Stashes are a stack — you cannot reorder directly |
Common Stash Workflows
| Item | Description |
|---|---|
Quick Context Switch | stash → switch branches → work → switch back → stash pop |
Pull with Local Changes | stash → pull → stash pop (cleaner than merge) |
Experiment Safely | stash working state → try an idea → pop to restore if needed |
Patch Sharing | stash → git stash show -p > fix.patch (share as patch file) |
Pre-Rebase Safety | stash before rebase — easy rollback if rebase goes wrong |
Code Review Prep | stash unrelated changes so reviewers see only relevant diff |
Testing Clean State | stash → run tests on clean HEAD → pop to resume work |
Partial Commit | stash some changes → commit the rest → pop to continue |
Pro Tip: Name your stashes with `git stash push -m 'description'` — you'll thank yourself when you have 10+ entries.