πŸ“‹ Cheat Sheets
Β· 3 min read
Last updated on

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

Quick access: Raycast lets you search commands, snippets, and cheat sheets instantly from your keyboard. Free for Mac.

πŸ“˜