Git & Command Line Tutorial · Branching and Collaboration · Lesson 18 of 20
Stashing Work in Progress
Put unfinished changes aside with git stash to switch branches or pull, then bring them back with stash pop.
When to stash
You're halfway through a change and need to switch branches to fix an urgent bug, but you're not ready to commit. Stash saves your uncommitted changes and gives you a clean working directory:
| Command | Does |
|---|---|
git stash push -m "wip: header" |
Save changes with a description (-u includes untracked files) |
git stash list |
Show saved stashes |
git stash pop |
Re-apply the latest stash and remove it |
git stash apply stash@{1} |
Re-apply a specific stash and keep it |
git stash drop |
Delete a stash |
Stashes are local and easy to forget. For anything longer than a quick interruption, a work-in-progress commit on a branch is safer.
git init -b main --quiet site && cd site
printf "<h1>Shop</h1>\n<p>Welcome!</p>\n<main>products</main>\n<p>Contact us</p>\n<footer>(c) Shop</footer>\n" > index.html
git add . && git commit -m "Add page" --quiet
sed -i 's#<footer>.*#<footer>(c) 2026 Shop, new footer in progress</footer>#' index.html
git stash push -m "wip: new footer" --quiet
echo "working tree clean? $(git status --short | wc -l | tr -d ' ') changed files"
git switch -c fix/title --quiet
sed -i '1s/Shop/Our Shop/' index.html && git commit -am "Fix title" --quiet # line 1 only
git switch main --quiet && git merge fix/title --quiet
git stash list
git stash pop --quiet
cat index.html # the fixed title and the unfinished footer, together
Output
working tree clean? 0 changed files
stash@{0}: On main: wip: new footer
Auto-merging index.html
<h1>Our Shop</h1>
<p>Welcome!</p>
<main>products</main>
<p>Contact us</p>
<footer>(c) 2026 Shop, new footer in progress</footer>Run this on your computer — see “Get Started” for setup.
Test yourself
What does git stash pop do?
Deletes all stashesRe-applies the most recent stash and removes it from the stash listPushes the stash to the remoteCommits the stash
Show answer
Answer: Re-applies the most recent stash and removes it from the stash list