Stash Workflow Practice
What you'll build
A repository where you simulate an interrupted workflow: you are mid-feature, an urgent bug needs fixing on main, you stash your work, fix the bug, then pop the stash to resume.
Goals
- Stash uncommitted changes with git stash
- Switch branches and fix an urgent issue
- Restore stashed changes with git stash pop
- Understand the stash stack (list, apply, drop)
Prerequisites
- git init, add, commit, branch, checkout
Steps
- 1
Set up the scenario
Create a repo with an initial commit on main, then start working on a feature branch with uncommitted changes.
Codemkdir stash-practice cd stash-practice git init echo "console.log('app')" > app.js git add . git commit -m "Initial app" git checkout -b feature/new-ui echo "// new UI work in progress" >> app.js echo "const ui = 'new';" >> app.jsExpected result
You are on feature/new-ui with uncommitted changes to app.js.
- 2
Stash your work to fix an urgent bug
An urgent bug is reported on main. Stash your feature work, switch to main, and fix the bug. Stashing saves your changes temporarily and cleans the working directory.
Codegit stash git checkout main echo "// bugfix: fix crash" >> app.js git add app.js git commit -m "Fix urgent crash bug"Expected result
Your feature changes are stashed; main has a new bugfix commit.
Hint
Run git stash list to see your stashed changes.
- 3
Return to your feature and restore work
Switch back to the feature branch and pop the stash to restore your uncommitted changes. Your work-in-progress is back exactly as you left it.
Codegit checkout feature/new-ui git stash pop git statusExpected result
Your stashed changes are restored; app.js shows the new UI work.
- 4
Continue and commit your feature
Now that your work is restored, finish the feature and commit it. The stash workflow let you handle an interruption without losing your work.
Codegit add app.js git commit -m "Add new UI work in progress"Expected result
Your feature work is committed on the feature branch.
- 5
Verify repository state
Use git status and git log to confirm the repository is clean and the commit history matches expectations. Before any destructive operation, checking the current state is a Git best practice.
Codegit status # Should show: nothing to commit, working tree clean git log --oneline -5 # Review the last 5 commits to confirm history git branch -v # List branches with last commit infoExpected result
git status shows a clean working tree; git log shows the expected commit history.
Try it yourself
What you learned
You practiced the stash workflow — the real-world technique for handling interruptions without losing uncommitted work. Stash, switch, fix, return, pop.
Related Resources
Related Lessons
- git stash
Learn stash, pop, list, and drop.
Related Cheatsheets
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.