← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Git Stash

Git 1.5 Beginner
debt(d7/e3/b3/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note automated=no and the only signal is accumulation of unnamed stashes visible in git stash list — there is no automated lint or SAST tool that flags stash misuse. A developer or reviewer must manually inspect the stash list or notice lost work after a machine wipe.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix indicates adopting git stash push -m 'description', using --patch for partial stashing, and preferring short-lived branches. This is a small behavioral change and minor refactor of workflow habits rather than a single one-liner swap, but does not span multiple files or require architectural rework.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). Stash misuse is scoped to an individual developer's local workflow and the local .git directory. It does not impose a persistent tax on the broader codebase or other team members — though lost stashes can cause rework, the structural burden is contained to one developer's context at a time.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field explicitly states developers treat stash as safe long-term storage, not realising stashes are local-only and not pushed to remote. Additionally, git stash pop silently drops the stash even on merge conflict (a behavior that contradicts how most 'apply and revert on failure' patterns work elsewhere), making this a serious cognitive trap that contradicts expected behavior.

About DEBT scoring →

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}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 52
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 1 ping S 3 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 3 pings M 2 pings T 0 pings W
No pings yet today
Sogou 1 Perplexity 1
Perplexity 9 Amazonbot 7 Scrapy 5 Ahrefs 4 SEMrush 4 Google 3 ChatGPT 3 Bing 2 Majestic 1 Claude 1 Meta AI 1 PetalBot 1 Sogou 1
crawler 40 crawler_json 2
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


✓ schema.org compliant