Practical guideTested1 min read
Git stash: put unfinished work aside and bring it back
Advertisement
When to use it
You changed a file but need to switch tasks and the work is not ready to commit.
git stash
git stash popgit stash list shows saved stashes.
Steps in order
- In the middle of unfinished work, run
git stash. Files go back to the last commit. - Do the other task.
- See what is saved with
git stash list. - Get your work back with
git stash pop.
Untracked files
Pop, apply or drop
git stash poprestores the change and removes the stash entry.git stash applyrestores it and keeps the entry, so you can reuse it.git stash dropdeletes an entry.
Is stash safe for long-term storage?
It is meant for short breaks. Use a branch and a commit for work you want to keep for days.
Which branch does pop restore onto?
The one you are on when you run it, so you can stash on one branch and pop on another.
Source: https://git-scm.com/docs/git-stash
Full kit: Git Survival Kit