Git Stash Cheat Sheet β Every Command with Examples
Some links in this article are affiliate links. We earn a commission at no extra cost to you when you purchase through them. Full disclosure.
Click any item to expand the explanation and examples. For a broader overview, see our complete Git guide or learn how Git actually works under the hood.
πΎ Save
git stash save
Stash all tracked, modified files. Working directory becomes clean.
git stash # Stash changes
git stash -m "work in progress" # With a message
git stash -u # Include untracked files
git stash -a # Include untracked + ignored files
git stash --keep-index # Stash but keep staged changes
π€ Restore
git stash pop restore
Apply the most recent stash and remove it from the stash list.
git stash pop # Apply latest + delete from list
git stash pop stash@{2} # Apply specific stash + delete
If thereβs a conflict, the stash is NOT dropped. Resolve conflicts, then git stash drop.
git stash apply restore
Apply a stash but keep it in the stash list (useful if you want to apply to multiple branches).
git stash apply # Apply latest, keep in list
git stash apply stash@{1} # Apply specific stash
π Manage
git stash list / show / drop manage
git stash list # List all stashes
git stash show # Show latest stash diff summary
git stash show -p # Show latest stash full diff
git stash show stash@{1} -p # Show specific stash diff
git stash drop # Delete latest stash
git stash drop stash@{2} # Delete specific stash
git stash clear # Delete ALL stashes
git stash branch <name> manage
Create a new branch from the stash β useful when your stash conflicts with current branch.
git stash branch my-feature # Create branch + apply stash
git stash branch fix stash@{1} # From specific stash
π― Partial Stash
git stash --patch advanced
Interactively choose which changes to stash. Git shows each hunk and asks whether to stash it.
git stash --patch # Pick which hunks to stash
git stash -p # Short form
Respond with y (stash this hunk), n (skip), s (split into smaller hunks), or q (quit).
git stash push -- <path> advanced
Stash only specific files instead of everything.
git stash push -- src/app.js # Stash one file
git stash push -- src/ lib/ # Stash specific directories
git stash push -m "wip api" -- src/api/ # With message
π Common Workflows
Stash before switching branches workflow
You have uncommitted changes but need to switch branches:
git stash -m "wip feature-x"
git checkout main
# do your work on main...
git checkout feature-x
git stash pop
Apply same stash to multiple branches workflow
Use apply instead of pop β it keeps the stash in the list:
git stash apply # Apply to current branch (stash stays)
git checkout other-branch
git stash apply # Apply same stash here too
git stash drop # Clean up when done
Recover a dropped stash workflow
Accidentally dropped a stash? Itβs still in Gitβs reflog for ~30 days:
git fsck --no-reflogs | grep commit # Find dangling commits
git show <commit-hash> # Check if it's your stash
git stash apply <commit-hash> # Recover it
See also: Git cheat sheet | Git stash pop conflict fix | Git merge conflict fix | fatal: not a git repository fix
FAQ
Whatβs the difference between git stash pop and git stash apply?
git stash pop applies the stash AND removes it from the stash list. git stash apply applies it but keeps it in the list. Use apply when you want to apply the same stash to multiple branches, or when youβre not sure the apply will be clean.
Can I stash untracked files?
By default, git stash only stashes tracked files. To include untracked files: git stash -u (or --include-untracked). To also include ignored files: git stash -a (or --all).
What happens if git stash pop has conflicts?
The stash is applied but NOT dropped from the list (unlike a clean pop). Resolve the conflicts, then manually run git stash drop to remove the stash entry. See Git stash pop conflict fix.
Is there a limit to how many stashes I can have?
No hard limit. But stashes are meant to be temporary. If you have more than 5-10 stashes, youβre probably better off creating branches for that work. Use git stash list to review and git stash drop stash@{n} to clean up old ones.
Quick access: Raycast lets you search commands, snippets, and cheat sheets instantly from your keyboard. Free for Mac.