Lesson 23 / 28

git stash

Shelve uncommitted changes with git stash, then restore them with pop or apply when you are ready.

Shelve and restore

Stash saves your dirty working directory and reverts it to a clean state, so you can switch branches instantly.

git stash
# ...switch branches, fix something urgent...
git stash pop

Output:

Saved working directory and index state WIP on main: a1b2c3d ...

Multiple stashes

Stashes stack up — list and pick which one to restore.

git stash list
git stash apply stash@{1}

pop vs apply

stash pop applies and deletes the stash entry; stash apply applies but keeps it around in case you need it again.