Weekly Git Command #3: git stash

There are times when you’re in the middle of some work, but you’re not ready to commit yet, and suddenly, you need to switch branches or pull in new changes.
Before learning this command, situations like that usually meant either committing half-done work or copying changes somewhere else manually.
That’s where git stash comes in.
What git stash does
git stash temporarily saves your uncommitted changes and gives you a clean working directory, so you can switch context without losing your work.
Think of it as putting your changes aside for later.
Basic usage
git stash
This:
Saves your current changes
Resets your working directory to the last commit
You can now safely switch branches or pull updates.
Viewing your stashes
git stash list
This shows all saved stashes, for example:
stash@{0}: WIP on main: 1a2b3c4 fix validation bug
stash@{1}: WIP on feature/auth: add login checks
Restoring your changes
To reapply the most recent stash and remove it from the stash list:
git stash pop
If you want to apply it without removing it:
git stash apply
When git stash is useful
I’ve found git stash helpful when:
I need to quickly switch branches
I’m not ready to commit unfinished work
I want to pull or rebase without conflicts
It helps keep my commit history clean while staying flexible.
A quick note
By default, git stash saves:
Tracked files
Modified files
Untracked files are not included unless explicitly specified.
Final thoughts
git stash is one of those commands that quietly becomes essential once you understand it. It’s simple, powerful, and solves a very common workflow problem.
This post is part of my Weekly Git Command series, where I share Git commands I’m learning while contributing to Git via Outreachy.
Next Step: taking stashing a step further with git stash -p - the interactive mode!




