Selectively Stash Files with git stash push -m
Problem
You’re working on multiple files in a branch but need to temporarily set aside only some of them. Running git stash stashes everything, which isn’t what you want.
Solution
Use git stash push with file paths to selectively stash.
# Stash a specific file
git stash push -m "login form WIP" -- src/components/LoginForm.tsx
# Multiple files
git stash push -m "API refactor" -- src/api/user.ts src/api/auth.ts
# Entire directory
git stash push -m "style changes" -- src/styles/
The older git stash save is deprecated. push is more flexible and supports file-level granularity.
Managing stashes works the same way:
# List stashes
git stash list
# stash@{0}: On feature/login: login form WIP
# stash@{1}: On feature/login: API refactor
# Apply without removing
git stash apply stash@{0}
# Apply and remove
git stash pop stash@{0}
Key Points
git stash push -m "message" -- path/to/filestashes only specified filesgit stash saveis deprecated — usepushinstead- Always add
-mmessages to identify stashes later applykeeps the stash entry;popremoves it after applying