Stashing Work in Progress

git stash

Scenario: You're halfway through an edit when you need to switch branches - but Git won't let you because of uncommitted changes, and you're not ready to commit. git stash is the answer.

stash tucks your uncommitted changes away on a shelf and gives you a clean working directory. Later, you pop them back.

CommandDoes
git stashShelve current changes
git stash listShow stashes
git stash popRe-apply the latest stash and remove it
git stash applyRe-apply but keep it in the list
git stash dropDelete a stash
$ git stash
Saved working directory and index state WIP on main: a1b2c3d Add readme
$ git switch hotfix     # clean tree, switch freely
# ...fix the bug, come back...
$ git switch main && git stash pop
Tip: git stash pop = apply + remove. git stash apply = apply but keep a copy (useful if you want the same changes on multiple branches).