Skip to content

git stash

git stash temporarily shelves (stashes) changes you’ve made to the working tree so you can work on something else, then come back and restore the saved changes.

Terminal window
# Stash uncommitted changes (tracked files only)
git stash
# Stash with a descriptive message
git stash push -m "WIP: user authentication flow"
# Also stash untracked files
git stash push -u
# Also stash ignored files (rarely needed)
git stash push --all
Terminal window
# Apply the most recent stash and remove it from the stash list
git stash pop
# Apply without removing from the stash list
git stash apply
# Apply a specific stash
git stash pop stash@{2}
git stash apply stash@{2}
Terminal window
# List all stashes
git stash list
# stash@{0}: WIP on feature: abc1234 Add login form
# stash@{1}: On main: fix typo
# stash@{2}: WIP: user authentication flow
# Show a summary of what a stash contains
git stash show stash@{0}
# Show the full diff
git stash show -p stash@{0}
Terminal window
# Remove a specific stash
git stash drop stash@{1}
# Remove all stashes
git stash clear

If a stash would conflict with your current branch, create a new branch instead:

Terminal window
git stash branch feature/saved-work stash@{0}
# Creates a new branch at the commit the stash was made from,
# applies the stash, and drops it
Terminal window
# Stash only specific files
git stash push -m "partial stash" path/to/file.ts
# Stage the files you want to keep, stash the rest
git add important-file.ts
git stash push --keep-index -m "stash everything except staged"
Terminal window
# Working on a feature, urgent bug report arrives
git stash push -m "WIP: feature/dashboard - half done"
# Fix the bug
git switch main
git switch -c hotfix/login-crash
# ... fix ...
git commit -m "Fix crash on login with empty email"
git switch main
git merge hotfix/login-crash
# Return to feature work
git switch feature/dashboard
git stash pop

An alternative to git stash is a “WIP commit”:

Terminal window
git add .
git commit -m "WIP: do not merge"
# Later, undo the WIP commit (keep changes staged)
git reset --soft HEAD~1

WIP commits are visible in history and can be pushed to a remote branch (good for backing up work in progress). Stashes are local-only.

  • Stashes are local — they don’t push to remote. If you lose your machine, you lose your stashes
  • git stash pop applies the stash and deletes it. If there’s a conflict, the stash is not deleted — resolve and run git stash drop manually
  • By default, git stash does not stash untracked files. Use -u to include them