Git Stash is a command that temporarily saves your uncommitted changes in a safe place so you can come back to them later.
It's Git's way of saying: don't lose my work, just get it out of my way for now.
When you run it, your working directory becomes completely clean — as if you never made any changes — freeing you to switch to another branch.
Why Use Git Stash?
Most developers have been here. It's Friday afternoon, you're deep into a new feature, and suddenly a message comes in — production is down. You need to switch context immediately.
You have two options:
A) Commit your broken, half-finished code (not recommended).
B) Use git stash to shelve your changes, clean up your environment, switch to the right branch, and fix the issue.
Git stash behaves like a stack data structure. That means the last item pushed is the first one out (LIFO — Last In First Out).
The Drawer Analogy
Your desk is covered with half-finished work. An urgent task comes in and you need to clear the space fast. You put everything in a drawer, handle the urgent task, then pull it back out and pick up right where you left off.
git stash = put it in the drawer.
git stash pop = take it out and empty the drawer.
git stash apply = take a copy out but leave the original inside.
git stash
git checkout hotfix
# apply the fix
git commit -m "fix: production issue"
git checkout feature-branch
git stash pop
How to Use Git Stash? Commands and Options
- git stash: Save your changes and clean the working directory (writing git stash push is recommended).
- git stash pop: Restore the last stash and remove it from the list.
- git stash apply: Restore the last stash but keep it in the list.
- git stash list: Lists all stashed entries. The most recent is always at the top.
- git stash show: Shows what's inside a stash. Accepts flags like -p stash@{0} for a full diff.
- git stash branch: Applies the stash by creating a new branch. Lesser known but very effective — it reduces conflict risk because the new branch starts from the exact commit where the stash was created.
- git stash drop: Removes a specific stash from the list. You can target one by index: stash@{1}.
- git stash clear: Warning — permanently deletes the entire stash list. This cannot be undone.
git stash and git stash pop are best friends. They're the most widely used pair because they follow simple stack logic: push your changes with stash, pull the latest back with pop.
Git Stash Pop vs Apply: What's the Difference?
Use pop when you're ready to resume work and no longer need the stash. Use apply when you want the changes back but also want to keep a copy in the list — for example, when applying the same changes across multiple branches.
Say you built a new feature and have two branches running different configurations. You can apply the same stash to both using git stash apply.
| Feature | git stash pop | git stash apply |
|---|---|---|
| Result | Restores changes. | Restores changes. |
| Removes from list | Yes (automatic) | No (keeps it) |
| Best for | Resuming work where you left off. | Applying the same changes to multiple branches. |
| Conflict safety | If a conflict occurs, the stash is not deleted — you're safe. | Never deleted anyway — always safe. |
In short: If you're done with the stash once you restore it, use pop. If you might need it again somewhere else, use apply.
Important Details
Untracked files are not included by default
Git won't stash untracked files unless you explicitly tell it to:
git stash --include-untracked or the shorthand git stash -u. To also include ignored files, use git stash -a.
You can have multiple stashes
As we mentioned, the stash works as a stack — last in, first out. If you have multiple stashes, git stash list might look like this:
stash@{0}: WIP on main: login page
stash@{1}: WIP on main: payment screen draft
stash@{2}: WIP on develop: api integration
You can name your stashes
Naming is invaluable once you have more than one stash. The syntax is very similar to git commit.
A single stash rarely needs a name. But once you've stashed multiple things in one day — or come back days later asking "what did I save?" — WIP on main: abc1234 won't ring any bells.
git stash push -m "login page half done — enjoy the weekend!"
# Unnamed stash list — tells you nothing
stash@{0}: WIP on main: a1b2c3d
stash@{1}: WIP on main: a1b2c3d
stash@{2}: WIP on develop: a1b2c3d
# Named stash list — readable at a glance
stash@{0}: On main: login form validation incomplete
stash@{1}: On main: payment screen layout changes
stash@{2}: On develop: api timeout issue under investigation
Retrieving a Specific Stash
By default, pop and apply both target the most recent entry. Most developers work with a single stash at a time, but you're not limited to one — you can retrieve any entry by its index:
git stash apply stash@{1}
Will I lose my work if I stash it?
No. Git stash saves your changes safely in the local repository. As long as your machine doesn't crash and you don't delete the .git folder, your work is safe. Similarly, if a conflict occurs while restoring a stash, Git won't remove it from the list — it stays put until the conflict is resolved. The one thing to watch out for is accidentally running git stash clear.
Git Stash Command Reference
| Goal | Command |
|---|---|
| Stash your changes | git stash |
| Include untracked files | git stash -u |
| List all stashes | git stash list |
| Restore latest and remove from list | git stash pop |
| Restore but keep in list | git stash apply |
| Restore a specific stash | git stash apply stash@{2} |
| Clear the entire list | git stash clear |