Git Stash
Also Known As
git stash
stash pop
stash apply
TL;DR
Temporarily shelves uncommitted changes so you can switch context — work in progress is saved to a stack and restored when you return.
Explanation
git stash push saves tracked changes (and optionally untracked with -u) to a stack. git stash pop restores the most recent stash and removes it. git stash apply restores without removing. git stash list shows all stashes with indices. git stash show -p stash@{n} shows the diff. Stashes are named with -m for clarity. A common mistake: stashing without a message makes stash@{3} meaningless two weeks later. Stash is useful for quick context switches but should not replace proper branching for long-lived work.
Diagram
flowchart LR
DIRTY[Working directory<br/>uncommitted changes] -->|git stash push -u -m name| STACK[(Stash stack)]
STACK -->|git stash pop| RESTORED[Changes restored<br/>stash removed]
STACK -->|git stash apply| APPLIED[Changes applied<br/>stash kept]
subgraph Commands
LIST[git stash list<br/>see all stashes]
SHOW[git stash show -p stash@0<br/>see diff]
DROP[git stash drop stash@0<br/>delete one]
CLEAR[git stash clear<br/>delete all]
end
subgraph When_to_Use
SWITCH[Need to switch branch quickly]
PULL[Need to pull before committing]
EXPERIMENT[Trying a different approach]
end
style STACK fill:#6e40c9,color:#fff
style RESTORED fill:#238636,color:#fff
Common Misconception
✗ git stash is a safe long-term storage — stash entries have no expiry but are not backed up with the remote; they live only in the local .git directory.
Why It Matters
Stash prevents the common 'I need to switch branches but have uncommitted work' problem without creating a messy WIP commit.
Common Mistakes
- Stashing without a message — stash@{2} is meaningless; use git stash push -m 'WIP: payment refactor'.
- git stash pop when a merge conflict occurs — pop removes the stash even if the apply fails; use git stash apply then manually drop.
- Accumulating many stashes — more than 2-3 stashes signals a branching problem, not a stash use case.
- Not stashing untracked files — git stash push -u includes new untracked files that plain stash misses.
Code Examples
✗ Vulnerable
# Multiple unnamed stashes — impossible to identify:
git stash # stash@{0}
git stash # stash@{1} — what was this?
git stash # stash@{2} — no idea
git stash list
# stash@{0}: WIP on main: abc1234 fix typo
# stash@{1}: WIP on main: abc1234 fix typo
# stash@{2}: WIP on main: abc1234 fix typo
✓ Fixed
# Named stashes + include untracked:
git stash push -u -m 'WIP: payment webhook handler'
git stash list
# stash@{0}: On feature/payments: WIP: payment webhook handler
# Apply without removing (safer for conflicts):
git stash apply stash@{0}
# Resolve any conflicts, then:
git stash drop stash@{0}
References
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
20
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Perplexity 8
Amazonbot 6
Majestic 1
Ahrefs 1
Google 1
Also referenced
How they use it
crawler 17
Related categories
⚡
DEV INTEL
Tools & Severity
🟢 Low
⚙ Fix effort: Low
⚡ Quick Fix
Use git stash push -m 'description' to name stashes; use git stash push --patch for partial stashing; prefer short-lived feature branches over stashes for work-in-progress
📦 Applies To
git 1.5
any
🔗 Prerequisites
🔍 Detection Hints
Accumulation of unnamed stashes git stash list showing stash@{0..10} with no descriptions
Auto-detectable:
✗ No
git
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: Low
Context: File