Stash as a Workbench

Three real interruptions. Three genuinely different ways to use git stash.

git stash sets aside real, uncommitted work — without committing it — so the working directory is genuinely clean for something else. This lab runs through three real scenarios where that matters in different ways: a plain interruption (stash, handle it, come back), juggling two real stashes at once (and needing the older one specifically, not just the most recent), and stashing only what is actually staged, leaving other real, unstaged work exactly where it was.

A Plain, Real Interruption

git stash push -m "wip: description"
# ...handle the urgent thing...
git stash pop

Real, uncommitted work set aside with a genuine, searchable message, restored the moment it is safe to return to it.

Two Real Stashes, the Older One Needed

git stash list
git stash apply stash@{1}

apply (unlike pop) leaves the stash entry in the list afterward — useful when the SAME real stashed change might be needed again, or when a newer stash still needs handling separately.

Only the Real Staged Part

git stash push --staged -m "wip: staged part only"

Stashes exactly what is staged, leaving any other real, unstaged edits in the working directory completely untouched.

git stash apply vs. git stash pop

Both restore a real stashed change — pop also removes it from the stash list afterward, apply leaves it there. Confirmed directly in this lab: applying an older stash by index left it available for cleanup separately from the newer one.

git stash push --staged

Stashes only what is currently staged, leaving unstaged real changes in the working directory exactly as they were. Confirmed directly in this lab: a second file's real, unstaged edit survived completely untouched.

⏸️ A Plain Interruption, Handled

Stash real mid-edit work, handle something else, come back.

cd ~/team-recipes && printf '\nTip: let dough rest 10 minutes before baking.\n' >> cookies.md && git stash push -m 'wip: cookie dough resting tip'
cd ~/team-recipes && git status
cd ~/team-recipes && git switch -c hotfix/urgent-typo
cd ~/team-recipes && sed -i 's/Trail Mix/Trail Mix Snack/' trail-mix.md && git add trail-mix.md && git commit -m 'Fix trail mix recipe title'
cd ~/team-recipes && git switch master && git merge --no-ff hotfix/urgent-typo -m "Merge branch 'hotfix/urgent-typo'"
cd ~/team-recipes && git branch -d hotfix/urgent-typo
cd ~/team-recipes && git stash list
cd ~/team-recipes && git stash pop
cd ~/team-recipes && git add cookies.md && git commit -m 'Add dough-resting tip to cookie recipe'

student@lab:~$ cd ~/team-recipes && printf '\nTip: let dough rest 10 minutes before baking.\n' >> cookies.md && git stash push -m 'wip: cookie dough resting tip' Saved working directory and index state On master: wip: cookie dough resting tip student@lab:~$ cd ~/team-recipes && git status On branch master Your branch is ahead of 'origin/master' by 115 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean student@lab:~$ cd ~/team-recipes && git switch -c hotfix/urgent-typo Switched to a new branch 'hotfix/urgent-typo' student@lab:~$ cd ~/team-recipes && sed -i 's/Trail Mix/Trail Mix Snack/' trail-mix.md && git add trail-mix.md && git commit -m 'Fix trail mix recipe title' [hotfix/urgent-typo 150687d] Fix trail mix recipe title 1 file changed, 1 insertion(+), 1 deletion(-) student@lab:~$ cd ~/team-recipes && git switch master && git merge --no-ff hotfix/urgent-typo -m "Merge branch 'hotfix/urgent-typo'" Switched to branch 'master' Your branch is ahead of 'origin/master' by 115 commits. (use "git push" to publish your local commits) Merge made by the 'ort' strategy. trail-mix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) student@lab:~$ cd ~/team-recipes && git branch -d hotfix/urgent-typo Deleted branch hotfix/urgent-typo (was 150687d). student@lab:~$ cd ~/team-recipes && git stash list stash@{0}: On master: wip: cookie dough resting tip student@lab:~$ cd ~/team-recipes && git stash pop On branch master Your branch is ahead of 'origin/master' by 117 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: cookies.md no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (a3afc82d625867e7c7901e823b6dc7d59e70cf03) student@lab:~$ cd ~/team-recipes && git add cookies.md && git commit -m 'Add dough-resting tip to cookie recipe' [master 18709c2] Add dough-resting tip to cookie recipe 1 file changed, 2 insertions(+)

🔢 Two Real Stashes, the Older One

Apply stash@{1} specifically, leaving the newer stash for later.

cd ~/team-recipes && printf '\nTip: use very ripe bananas for best flavor.\n' >> banana-bread.md && git stash push -m 'wip: banana bread ripeness tip'
cd ~/team-recipes && printf '\nTip: brew iced tea double-strength before icing.\n' >> iced-tea.md && git stash push -m 'wip: iced tea strength tip'
cd ~/team-recipes && git stash list
cd ~/team-recipes && git stash apply stash@{1}
cd ~/team-recipes && git add banana-bread.md && git commit -m 'Add ripeness tip to banana bread recipe'
cd ~/team-recipes && git stash list

student@lab:~$ cd ~/team-recipes && printf '\nTip: use very ripe bananas for best flavor.\n' >> banana-bread.md && git stash push -m 'wip: banana bread ripeness tip' Saved working directory and index state On master: wip: banana bread ripeness tip student@lab:~$ cd ~/team-recipes && printf '\nTip: brew iced tea double-strength before icing.\n' >> iced-tea.md && git stash push -m 'wip: iced tea strength tip' Saved working directory and index state On master: wip: iced tea strength tip student@lab:~$ cd ~/team-recipes && git stash list stash@{0}: On master: wip: iced tea strength tip stash@{1}: On master: wip: banana bread ripeness tip student@lab:~$ cd ~/team-recipes && git stash apply stash@{1} On branch master Your branch is ahead of 'origin/master' by 118 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: banana-bread.md no changes added to commit (use "git add" and/or "git commit -a") student@lab:~$ cd ~/team-recipes && git add banana-bread.md && git commit -m 'Add ripeness tip to banana bread recipe' [master ee37587] Add ripeness tip to banana bread recipe 1 file changed, 2 insertions(+) student@lab:~$ cd ~/team-recipes && git stash list stash@{0}: On master: wip: iced tea strength tip stash@{1}: On master: wip: banana bread ripeness tip

🎯 Only the Real Staged Part

One file staged, one not — stash exactly the staged change.

cd ~/team-recipes && printf '\nTip: rest the batter for a fluffier bake.\n' >> banana-bread.md
cd ~/team-recipes && printf '\nTip: add a squeeze of lemon for brightness.\n' >> iced-tea.md
cd ~/team-recipes && git add banana-bread.md
cd ~/team-recipes && git status
cd ~/team-recipes && git stash push --staged -m 'wip: staged-only banana bread rest tip'
cd ~/team-recipes && git status
cd ~/team-recipes && git checkout -- iced-tea.md
cd ~/team-recipes && git stash pop
cd ~/team-recipes && git add banana-bread.md && git commit -m 'Add batter resting tip to banana bread recipe'
cd ~/team-recipes && git stash list
cd ~/team-recipes && git stash drop

student@lab:~$ cd ~/team-recipes && printf '\nTip: rest the batter for a fluffier bake.\n' >> banana-bread.md student@lab:~$ cd ~/team-recipes && printf '\nTip: add a squeeze of lemon for brightness.\n' >> iced-tea.md student@lab:~$ cd ~/team-recipes && git add banana-bread.md student@lab:~$ cd ~/team-recipes && git status On branch master Your branch is ahead of 'origin/master' by 119 commits. (use "git push" to publish your local commits) Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: banana-bread.md Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: iced-tea.md student@lab:~$ cd ~/team-recipes && git stash push --staged -m 'wip: staged-only banana bread rest tip' Saved working directory and index state On master: wip: staged-only banana bread rest tip student@lab:~$ cd ~/team-recipes && git status On branch master Your branch is ahead of 'origin/master' by 119 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: iced-tea.md no changes added to commit (use "git add" and/or "git commit -a") student@lab:~$ cd ~/team-recipes && git checkout -- iced-tea.md student@lab:~$ cd ~/team-recipes && git stash pop On branch master Your branch is ahead of 'origin/master' by 119 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: banana-bread.md no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (9e81c551bff8f7ecf7ffe6ed84c7e866275ed159) student@lab:~$ cd ~/team-recipes && git add banana-bread.md && git commit -m 'Add batter resting tip to banana bread recipe' [master 36f8555] Add batter resting tip to banana bread recipe 1 file changed, 2 insertions(+) student@lab:~$ cd ~/team-recipes && git stash list stash@{0}: On master: wip: iced tea strength tip stash@{1}: On master: wip: banana bread ripeness tip student@lab:~$ cd ~/team-recipes && git stash drop Dropped refs/stash@{0} (4e81aedc4f404da1a39a375a4939da21c1fe2ab3)

Lab 3.5.2 complete. Three real interruptions, three genuine stash techniques, everything cleaned up:\n\n\n Plain push/pop : ✅ handled\n Older stash by index : ✅ applied specifically\n Staged-only stash : ✅ unstaged work untouched\n

Enable JavaScript to run the live terminal and track your progress.