git stash temporarily shelves changes you have not committed so you can switch context — for example, to fix an urgent bug on another branch. Your working directory becomes clean, and you can pop the stash later to restore your work.
Git
Beginner
8 min read
git stash: Temporarily Save Work
Example
# You are halfway through a feature when an urgent bug comes in.
# Stash your current changes:
git stash
# Saved working directory and index state WIP on main: abc1234
# Give the stash a descriptive name:
git stash save "WIP: add user profile page"
# Also stash untracked files:
git stash -u
# Your working directory is now clean — switch to fix the bug:
git switch hotfix/critical-bug
# ... fix, commit, and push the bug fix ...
git switch main
# List all stashes:
git stash list
# stash@{0}: WIP on main: add user profile page
# stash@{1}: On main: experiment with dark mode
# Apply the most recent stash (keeps it in the list):
git stash apply
# Apply and remove from the list:
git stash pop
# Apply a specific stash:
git stash apply stash@{1}
# Remove a specific stash:
git stash drop stash@{1}
# Remove all stashes:
git stash clear