How To Stash Changes in Git: A Simple, Practical Guide
When you’re working on code and suddenly need to switch tasks, Git stash is the feature that lets you “put your unfinished work on a shelf” without committing it. You can then come back later, pick it up, and continue where you left off.
This guide explains what Git stash does, how to use it step-by-step, and what changes depending on your setup and workflow.
What Does “Stashing” Changes in Git Mean?
In plain terms, stashing in Git means:
- You have uncommitted changes in your working directory
- You’re not ready to commit them yet
- You need to switch branches, pull updates, or try something else
- You want to save your work-in-progress temporarily and come back to it later
Git stash:
- Saves your uncommitted changes (by default, tracked files only)
- Cleans your working directory (restores it to the last commit)
- Lets you reapply those saved changes later
Think of it like this:
- Commit = “This is a permanent, meaningful checkpoint in history.”
- Stash = “This is a temporary note of what I was doing; I’ll finish it later.”
Basic Git Stash Commands You’ll Actually Use
1. Stash your current changes
git stash This:
- Saves changes to tracked files (files Git already knows about)
- Reverts your working directory to the last commit
You can also add a label so you remember what the stash is about:
git stash push -m "WIP: add login validation" Older Git versions often show git stash save "message", which is similar, but push is the more modern form.
2. See what you have stashed
git stash list You’ll see something like:
stash@{0}: On main: WIP: add login validation stash@{1}: On feature-branch: refactor profile page Each stash has an index (stash@{0}, stash@{1}, etc.) and an optional message.
3. Reapply (and remove) the latest stash
git stash pop This:
- Applies the most recent stash (
stash@{0}) to your working directory - Removes it from the stash list
If there are conflicts, Git will tell you, and you’ll resolve them like a normal merge or rebase conflict.
4. Reapply (but keep) the latest stash
git stash apply This:
- Applies the most recent stash
- Keeps it in the stash list
Useful when:
- You want to reuse the same stash on another branch
- You want to be safe and not lose the stash immediately
5. Apply or pop a specific stash
If you have multiple stashes:
git stash list git stash apply stash@{2} # or git stash pop stash@{2} This targets one specific stash instead of the latest.
6. Stash including untracked files
By default, Git stash ignores untracked files (new files not yet added to Git).
To stash tracked + untracked files:
git stash push -u Or the longer form:
git stash push --include-untracked To also include ignored files (less common):
git stash push -a # or git stash push --all 7. Remove a stash without applying it
git stash drop stash@{1} To clear all stashes:
git stash clear What Git Stash Actually Saves (and What It Doesn’t)
When you run git stash, Git captures:
- Changes to tracked files (by default)
- Optionally, untracked and ignored files if you use the right flags (
-u,-a)
It does not:
- Create a normal commit in your main history
- Automatically sync across machines (stashes are local to your clone)
- Replace proper commits for work you want to share or keep long term
Stashes live in a special area of your local Git repository. They are essentially lightweight commits that Git stores in a stack.
Common Scenarios Where Git Stash Helps
1. You need to switch branches mid-task
You’re halfway through a feature on feature-x, then you’re asked to fix a quick bug on main.
Typical flow:
# on feature-x with uncommitted changes git stash push -m "WIP: feature-x" git checkout main # fix the bug, commit, push, etc. git checkout feature-x git stash pop Your work-in-progress is now back on feature-x.
2. You want to pull changes but have local modifications
Some Git operations (like git pull) complain if your working directory isn’t clean.
You can:
git stash push -m "Before pull" git pull git stash pop If there are conflicts, you resolve them and keep going.
3. You’re experimenting with a risky change
You want to try something without committing, but you also want a safe way to reset.
One approach:
git stash push -m "Before experiment" # try experimental edits # if you don't like it: git reset --hard HEAD git stash pop # back to where you were Options and Behaviors That Change How Stash Works
How you use git stash can vary a lot depending on:
| Variable / Factor | Why it matters |
|---|---|
| Git version | Some options (git stash push -m) behave slightly differently in older Git. |
| Tracked vs. untracked files | Determines whether you need -u / --include-untracked. |
| Branching strategy | Affects whether you pop stashes on the same branch or another one. |
| Team workflow | Influences whether stashes are used heavily or avoided in favor of commits. |
| IDE / GUI tools | Many tools have visual stash management that wraps these commands. |
| Comfort with Git internals | Determines whether you inspect stashes, cherry-pick from them, etc. |
These variables shape how you set up your stash habits.
Different Ways People Use Git Stash
1. Minimal, “only when stuck” usage
Profile:
- Uses Git mostly from the command line
- Prefers simple, memorable commands
- Avoids complexity
Typical pattern:
git stashgit checkout other-branchgit checkout original-branchgit stash pop
This approach usually:
- Stashes only tracked files
- Keeps a short stash list, often only one at a time
2. Heavy stash users with multiple work streams
Profile:
- Works on several tasks at once
- Frequently switches contexts
- Needs labels to remember what each stash is
Typical pattern:
- Uses
git stash push -m "WIP: description" - Regularly checks
git stash list - Applies specific stash entries (
git stash apply stash@{3}) - Sometimes keeps stashes around for longer as temporary backups
Here, the naming and indexing of stashes matter more.
3. Working with many untracked files
Profile:
- Generates new files frequently (e.g., prototypes, test data, scratch code)
- May not want to
git addeverything yet
Typical pattern:
- Uses
git stash push -uto include untracked files - Sometimes uses
git stash push -aif ignored files are involved
This can be powerful, but also riskier: you’re temporarily hiding more of your working directory, so you need to keep track of what’s in which stash.
4. Stash vs. feature branches
Some people prefer to:
- Create short-lived branches for experiments or WIP
- Commit small “WIP” or “draft” commits instead of stashes
Others like:
- Keeping the main history cleaner with fewer “junk” commits
- Using stashes as scratch space that won’t show up in shared history
Both are valid; which feels better depends on your comfort with branching, your team’s standards, and how often you revisit old experiments.
When Git Stash Might Not Be the Best Fit
Even though git stash is convenient, sometimes other tools or patterns work better:
If you need to share your work with teammates:
A real commit on a branch (even if marked WIP) is more visible and collaborative than a stash.If you want a permanent record of an experiment:
Commits are easier to browse and understand in history than old stash entries.If you frequently forget what’s in stashes:
Too many unnamed or unused stashes can cause confusion or accidental loss when clearing them.
In those cases, lightweight commits or dedicated branches are often safer.
The Missing Piece: Your Own Git Workflow
The core mechanics of git stash are straightforward:
git stash pushto save changesgit stash listto see what’s savedgit stash applyorpopto bring changes back- Optional flags like
-uor-ato control what gets stashed
What really shapes how you should use Git stash, though, is your own setup:
- How often you switch branches mid-task
- Whether you work solo or in a team with strict commit history rules
- How comfortable you are with creating and cleaning up feature branches
- How many untracked or generated files your workflow produces
- Whether you mostly use the command line, an IDE, or a Git GUI
Once you understand what stash does and the options it offers, the next step is looking at your own habits and project style to decide how heavily you lean on it—and where you might prefer branches, temporary commits, or other approaches instead.