Skip to main content

Git Stash Cheatsheet — save / pop / apply / drop / list / show / branch

Git stash is your 'save game' for uncommitted work. It temporarily shelves changes so you can switch branches, pull upstream changes, or start fresh — then restore your work later. This guide covers everything from basic stash-and-pop to advanced operations like stashing untracked files, partial stashes, and creating branches from stashed work.

Updated: 2026-07-15·20 commands

Quick Reference Table

OperationCommandUse Case
Stash all tracked changesgit stashQuick save, switch branches
Stash with messagegit stash push -m "msg"Document what you saved
Stash untracked files toogit stash push -uInclude new files
Stash everything (including ignored)git stash push -aFull workspace clean
Stash specific filesgit stash push -m "msg" Selective save
Stash interactively (hunk-by-hunk)git stash push -pPartial stash
List all stashesgit stash listSee what's saved
Show a stash's diffgit stash show -p [stash@{n}]Inspect stashed changes
Apply latest stash & keep itgit stash applyRestore without dropping
Apply and drop (one shot)git stash popDefault restore flow
Apply a specific stashgit stash apply stash@{2}Pick a particular save
Drop a specific stashgit stash drop stash@{2}Clean up old stashes
Drop all stashesgit stash clear⚠️ Irreversible cleanup
Create a branch from a stashgit stash branch [stash@{n}]Recover onto a new branch

git stash push — Save Your Work

The git stash push command (or the shorthand git stash) saves modified tracked files to a new stash entry and reverts your working directory to the last commit's state.

``bash # Basic save — just tracked files git stash

# Save with a descriptive message git stash push -m "WIP: refactor auth middleware"

# Stash untracked files as well git stash push -u

# Stash everything, including gitignored files git stash push -a

# Stash only specific files git stash push -m "config tweaks" src/config.ts

# Stash interactively — choose hunks one by one git stash push -p

# Keep staged changes, stash only unstaged modifications git stash push --keep-index `

> Pro tip: git stash push is the modern, feature-rich form. The old git stash save command is deprecated.

### Options Breakdown

FlagEffect
(none)Stash tracked files only
-u / --include-untrackedInclude untracked files
-a / --allInclude ignored files too
-m / --messageAttach a label for identification
-p / --patchInteractive hunk selection
--keep-indexLeave staged changes alone

git stash list / show — Inspect Stashes

`bash # List all stash entries git stash list

# Show summary with details git stash list --format="%gd: %gs (%cr)"

# Show what a stash changes (diffstat) git stash show stash@{0}

# Show full diff of a stash git stash show -p stash@{2}

# Show the latest stash's diff git stash show -p `

The git stash list output uses stash@{n} notation:

` stash@{0}: On main: WIP: refactor auth middleware stash@{1}: On feature/login: fix login form validation stash@{2}: On develop: debug console output cleanup `

The stash stack is LIFO (Last In, First Out). stash@{0} is always the most recent.

git stash pop / apply — Restore Changes

### git stash pop — Apply & Remove

Applies the stash and drops it from the stash list. This is the standard one-shot workflow.

`bash # Apply latest stash and remove it git stash pop

# Apply a specific stash and remove it git stash pop stash@{1} `

If conflicts arise during pop, the stash entry is not dropped — it's preserved so you can fix conflicts and try again.

### git stash apply — Apply & Keep

Applies the stash but keeps it in the stash list. Use this when you need to restore the same changes multiple times (e.g., cherry-pick a fix to several branches).

`bash # Apply latest stash, keep it git stash apply

# Apply a specific stash, keep it git stash apply stash@{3} `

Featuregit stash popgit stash apply
Restores changes
Drops from list
Use for one-time restore⭐⭐⭐⭐⭐
Use for multi-branch restore⭐⭐⭐⭐⭐
Behavior on conflictStash preservedStash preserved

git stash drop / clear — Clean Up

`bash # Drop a specific stash git stash drop stash@{1}

# Drop the latest stash git stash drop

# Clear all stashes (⚠️ irreversible) git stash clear `

> ⚠️ Warning: git stash clear deletes every stash entry permanently. There is no git stash undo. If you're unsure, drop individual stashes instead.

git stash branch — Recover onto a New Branch

If you stash changes on one branch and the working tree has drifted significantly, applying the stash can cause painful conflicts. git stash branch creates a new branch starting at the commit where the stash was created.

`bash # Create a branch from the latest stash git stash branch fix/login-issue

# Create a branch from a specific stash git stash branch fix/login-issue stash@{1} `

This command: 1. Checks out the commit the stash was based on 2. Creates a new branch at that commit 3. Applies the stash onto that branch 4. Drops the stash entry (like pop)

This is the safest way to recover work from an old stash that no longer cleanly applies to current main.

Practical Workflow Examples

### Example 1: Interrupt — switch to another branch urgently

`bash # You're working on feature-x, but a hotfix on main needs attention git stash push -m "WIP: feature-x progress" git checkout main # ... fix the bug, commit, push ... git checkout feature-x git stash pop `

### Example 2: Pull without committing

`bash # Need to git pull but have dirty working tree git stash push -m "before pull" git pull --rebase git stash pop `

### Example 3: Clean workspace for a clean build

`bash git stash push -u -m "clean build checkpoint" ./build.sh git stash pop `

### Example 4: Recover old stash that won't apply cleanly

`bash git stash list # stash@{4}: On adjust-pricing: price calculation rework git stash branch rework-pricing stash@{4} # Now working in a fresh branch at the original commit `

### Example 5: Test with and without your changes

`bash # Save changes git stash push -m "my feature changes" npm test # run tests without your changes git stash pop npm test # run tests with your changes `

### Example 6: Stash only staged changes for a partial commit

`bash git add src/app.ts # stage the 'safe' changes git stash push --keep-index # stash the rest of the messy work git commit -m "safe commit" git stash pop # bring back the messy work `

Common Troubleshooting

SymptomCauseFix
git stash apply fails with conflictsWorking tree has divergedUse git stash branch instead
git stash didn't save my new filesUntracked files excludedUse git stash push -u
Accidentally cleared my stashStash list is now emptyCheck with git stash list; if truly empty, it's gone — stash in regular intervals as a habit
Want to see what's in a stash without applyingUnsure of contentsgit stash show -p stash@{n}` to inspect the full diff

Stash(20)

CommandLevel
git stash
Stash the changes in a dirty working directory away
Basic
git stash pop
Apply the latest stash and remove it from the stash list
Basic
git stash list
List all stashes
Basic
git stash apply
Apply a stash without removing it from the stash list
Basic
git stash drop
Remove a single stash entry from the stash list
Basic
git stash show
Show the changes recorded in a stash
Basic
git stash branch
Create a new branch from a stash
Intermediate
git stash push -m
Stash changes with a description message
Basic
git stash push -u
Stash changes including untracked files
Intermediate
git stash push -a
Stash all files including ignored ones
Expert
git stash push -p
Interactive stash (select specific changes)
Expert
git stash push -k
Stash unstaged changes, keep staged content
Intermediate
git stash show -p
Show the full diff of a stash
Intermediate
git stash clear
Remove all stash entries
Intermediate
git stash apply --index
Apply stash and restore staged state
Intermediate
git stash pop --index
Pop stash and restore staged state
Intermediate
git stash list --format
List stash entries with custom format
Expert
git stash push -S
Stash only staged changes
Expert
git stash -- <pathspec>
Stash changes for specific paths only
Intermediate
git stash save
Stash changes (legacy syntax)
Basic

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-15.