How to stash changes in Git
· Category: Git
Short answer
Run git stash to save your current uncommitted changes and revert the working directory to HEAD.
Steps
- Stash current changes:
git stash push -m "WIP on feature"
- List stashes:
git stash list
- Apply the latest stash:
git stash pop
- Apply without removing:
git stash apply stash@{0}
Tips
- Stash is local and will not be pushed to remotes.
git stash -uincludes untracked files.- Name your stashes with messages for easier identification.
Common issues
- Forgetting about old stashes can lead to confusion; clean up with
git stash drop. - Stash does not stash ignored files unless you use
--all.