Stash unfinished work
Undoing mistakes · Article 8 of 9 · 2 min read
Park half done changes so you can switch branches cleanly.
The short version
git stash puts your uncommitted changes on a shelf and gives you a clean folder. git stash pop brings them back.
Details
Stashes belong to the repository, not to a branch, so you can stash on one branch and pop on another. New files are only stashed if you add -u.
Try it yourself
echo "draft" >> notes.txt
git stash
git status
git stash pop
git status
The first status shows a clean folder. After the pop, notes.txt is modified again.
Explain it to the duck
When would a stash be better than a commit?
Tested with: Git 2.51.
Where to go next
- Rebasing(opens in a new tab) Keep a branch history straight instead of merging.
- Git hooks(opens in a new tab) Run checks automatically before each commit.
- Continuous integration Run tests on every push so broken changes are caught early.