Skip to content

Git Stash and Temporary Changes โ€‹

Introduction โ€‹

git stash lets you shelve uncommitted work so you can switch tasks, pull updates, or apply emergency fixes without committing incomplete code.

What Stash Stores โ€‹

By default: modified tracked files + staged changes. Optionally untracked / ignored files.

Basic Usage โ€‹

bash
git stash push -m "WIP: form validation"
git stash list

Example list entry:

stash@{0}: On feature/form: WIP: form validation

Restoring Work โ€‹

bash
git stash apply stash@{0}   # Keep stash copy
git stash pop               # Apply then drop latest

Include Untracked Files โ€‹

bash
git stash push -u -m "WIP: add config prototype"

Include ignored files:

bash
git stash push -a -m "WIP: full env"

Partial Stash (Interactive) โ€‹

bash
git stash push -p -m "WIP: selected changes"

Viewing Stash Diff โ€‹

bash
git stash show stash@{1}
git stash show -p stash@{1}   # Full patch

Dropping / Clearing โ€‹

bash
git stash drop stash@{2}
git stash clear   # Dangerous: removes all stashes

Applying to Different Branch โ€‹

bash
git checkout feature/new-ui
git stash apply stash@{0}

Creating a Branch from a Stash โ€‹

bash
git stash branch feature/resume stash@{0}

Common Patterns โ€‹

ScenarioCommand
Pull changes but keep WIPgit stash push -m "WIP" && git pull && git stash pop
Hotfix on mainStash โ†’ switch โ†’ fix โ†’ return โ†’ pop
Clean workspace for buildStash uncommitted noise

When NOT to Use Stash โ€‹

  • Long-term storage (make a WIP commit instead)
  • Sharing with others (use a branch)
  • Binary-heavy work (may cause large object churn)

Alternatives โ€‹

NeedAlternative
Safe checkpointCommit to temp branch
Experimental spikefeature/spike-* branch
Quick discardgit restore

Troubleshooting โ€‹

IssueSolution
Conflict on applyResolve, git add, continue (stash already applied)
Lost stash after popRecover: git fsck --lost-found (sometimes)
Accidentally stashed untracked important filePrefer branches in future

Summary โ€‹

Stash is a tactical tool for short-lived interruptions. Use it deliberately; prefer explicit commits for durable progress.

Next Steps โ€‹

  • Undo operations (git-reset-revert-and-checkout-explained.md)
  • Deep conflict workflows (git-conflict-resolution-strategies.md)

Key Commands

bash
git stash push -m "msg"
git stash list
git stash show -p stash@{n}
git stash pop
git stash branch <name> stash@{n}