CodeOath
← All posts
Git65 min total · 17 parts

Git Internals and Workflows: Branching, Merging, and Rebasing

Contents — Part 12 of 17: Stashing Work in Progress
Part 12 of 17 · ~1 min

Stashing Work in Progress

git stash temporarily shelves uncommitted changes (both staged and unstaged, by default) so you can switch to a clean working tree — to pull the latest main, switch branches to look at something else, or handle an urgent interruption — without committing half-finished work just to get it out of the way:

git stash                 # shelve current changes, working tree becomes clean
git switch main
git pull
git switch feature
git stash pop              # re-apply the shelved changes and remove them from the stash list

git stash pop applies the most recent stash and removes it from the stash list; git stash apply applies it but leaves it in the list too, useful if you want to apply the same stashed changes to more than one branch. Stashes are stored as a special kind of commit internally, which is why git stash list can hold several independent stashes at once, each restorable individually by reference (git stash apply stash@{1}).