Menu
Coddy logo textTech

Git Stash

Last updated

git stash shelves your uncommitted changes and reverts your working tree to a clean state, so you can switch branches or pull without committing half-finished work. The changes go onto a stack you can reapply later with git stash pop (apply and remove) or git stash apply (apply and keep).

Try these in the terminal playground - a real shell in your browser, nothing to install.

Syntax

CommandWhat it does
git stashShelve tracked changes, clean the working tree
git stash -uAlso stash untracked files
git stash push -m "msg"Stash with a descriptive message
git stash push <file>Stash only a specific file
git stash listList all stashes
git stash popReapply the latest stash and remove it
git stash applyReapply the latest stash, keep it
git stash dropDelete the latest stash
git stash clearDelete all stashes

pop vs apply

Behaviorgit stash popgit stash apply
Reapplies the changesYesYes
Removes the stash afterYesNo
Good for reusing a stashNoYes

Git stash FAQ

What does git stash do?
It saves your uncommitted changes onto a stack and resets your working tree to the last commit, giving you a clean slate. Your changes aren't lost - they're shelved and can be reapplied later with git stash pop or git stash apply. It's handy when you need to switch branches but aren't ready to commit.
What's the difference between git stash pop and git stash apply?
Both reapply your most recent stash to the working tree. git stash pop also removes that stash from the stack afterward, while git stash apply leaves it on the stack so you can apply it again elsewhere. Use pop for a one-time restore, apply when you want to reuse the stash.
Does git stash include untracked files?
Not by default - a plain git stash only shelves tracked (modified) files. Add -u (git stash -u) to include untracked files, or -a to also include ignored files. Without those flags, new files you haven't git add-ed stay in your working tree.
How do I apply a specific stash?
Run git stash list to see them numbered like stash@{0}, stash@{1}, then git stash apply stash@{1} (or pop) to reapply a particular one. Each stash also shows the branch and message it was created with, so you can tell them apart.
Can I practice this online?
Yes. Open the terminal playground to run git stash in a real shell in your browser - nothing to install. Coddy's free interactive Git course also covers managing work in progress step by step.
Coddy programming languages illustration

Learn Git with Coddy

GET STARTED