Temporarily Storing Changes
Stash saves your uncommitted changes in temporary storage, letting you switch contexts without committing half-finished work. Think of it as a cargo hold for work in progress.
Basic Stash
git stashSaves tracked file changes and returns your working directory to the last commit.
Stash with a Message
git stash push -m "Work in progress on sensors"A descriptive message makes it much easier to find the right stash later.
Include Untracked Files
git stash -uBy default, stash only saves tracked files. The -u flag includes new, untracked files too.
List Your Stashes
git stash listOutput:
stash@{0}: WIP on main: abc123 Latest commit
stash@{1}: On feature: Work in progress on sensors
Apply a Stash
git stash apply # Apply the most recent stash
git stash apply stash@{1} # Apply a specific stashapply keeps the stash in the list after restoring it.
Pop a Stash
git stash poppop applies the stash and removes it from the list—the most common workflow.
Drop or Clear Stashes
git stash drop stash@{0} # Delete one stash
git stash clear # Delete all stashesInspect a Stash
git stash show -p stash@{0}Shows the full diff of what the stash contains before you apply it.
Common Use Cases
- Switching branches while you have uncommitted changes
- Pulling the latest changes without committing first
- Trying a different approach without losing the current one
- Handling an urgent bug in the middle of feature work
Workflow Example
# Working on a feature when an urgent bug arrives
git stash
# Switch and fix the bug
git switch main
# ...fix, commit, push...
# Return to your feature exactly where you left off
git switch feature-branch
git stash popStashing to a New Branch
git stash branch new-feature stash@{0}If applying a stash would conflict with your current branch, this creates a fresh branch from the commit where you stashed, then applies the changes there—conflict-free.
Best Practices
- Always add a message so old stashes are identifiable weeks later
- Don't let stashes pile up—review
git stash listregularly and drop what you no longer need - Stash is not a backup: it lives only in your local repository and is never pushed to a remote
Next: Marker Beacons
Your work-in-progress is safe in temporal storage. Next, learn git tag—placing permanent marker beacons on important moments like releases.