Difference between git stash pop and git stash apply
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
git stash pop and git stash apply both restore previously stashed changes to your working directory. The key difference is what happens to the stash entry afterward: pop removes it from the stash stack, while apply keeps it. This distinction matters when you need to apply the same stash to multiple branches or want a safety net before applying changes.
Quick Comparison
| Command | Applies Changes | Removes Stash Entry | Safe for Multi-Branch |
git stash pop | Yes | Yes (on success) | No |
git stash apply | Yes | No | Yes |
git stash pop
Applies the stash and immediately removes it from the stash list:
If there is a merge conflict during pop, the stash is not removed. You must resolve the conflict and then manually drop the stash:
git stash apply
Applies the stash but keeps it in the stash list:
This is useful when you want to apply the same changes to multiple branches:
Specifying Which Stash
Both commands default to the most recent stash (stash@{0}). You can specify a different one:
Stash Workflow Patterns
Quick Context Switch (pop)
Experimental Changes (apply)
Named Stashes
Stash with Specific Files
Viewing Stash Contents
Common Pitfalls
- Conflict handling:
git stash popdoes not remove the stash if there are conflicts. After resolving, you mustgit stash dropmanually. Many developers forget this, leaving stale stash entries. - Wrong branch: Popping a stash on the wrong branch applies those changes there. Since
popremoves the stash, you cannot easily undo this. Useapplywhen unsure, thendropafter confirming. - Stash index drift: Stash indices shift when you add or drop stashes.
stash@{1}after apopbecomes a different stash than before. Always checkgit stash listbefore applying by index. - Untracked files: By default,
git stashdoes not include untracked files. Usegit stash push --include-untrackedor-uto include them. - Stash is not a substitute for commits: Stashes are local and temporary. For work you want to preserve long-term, create a WIP commit on a branch instead.
Summary
git stash popapplies changes and removes the stash entry (unless there are conflicts)git stash applyapplies changes and keeps the stash entry for reuse- Use
applywhen you need the same stash on multiple branches or want a safety net - Use
popfor quick context switches where you just need to restore and move on - Always check
git stash listto verify which stash you are targeting
Related reading
- Difference between git stash pop and git stash apply
- Difference between HEAD and master or main
- Difference between 'rebase master' and 'rebase --onto master' from a branch derived from a branch of master
- Difference between stdmerge and stdinplace_merge?
- Differences between Git-scm, msysGit Git for Windows
- Differences between git pull origin master git pull origin/master
- Differences between git remote update and fetch?
- Differences between git submodule and subtree
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.