Difference between git stash pop and git stash apply
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
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

