Stashing changes with git stash
Sometimes you're mid-edit - not ready to commit, but you need a clean working
tree anyway (switch branches, pull someone else's work, whatever). Committing
half-finished work just to switch away and back is annoying. git stash is
the better move: it takes your uncommitted changes, tucks them away on a
shelf, and puts your working directory back to exactly what your last commit
looked like. git stash pop brings the shelved changes back later, right
where you left them.
Same starting point as the merge lesson: main has one commit (app.txt),
and this time it's been edited since - a real, uncommitted change sitting in
the working directory.
Your task: stash that edit, confirm the tree is clean, then pop it back
and commit it with the exact message Update app.txt.
You'll practice:
git stash - shelving uncommitted changes and getting a clean tree back
git stash pop - restoring what you shelved
- Recognizing that stash is for a few minutes, not long-term storage
Related reading: The Everyday Commands - What Each One Really Does →