
MaksymGit stash is one of those commands that feels minor until the day you desperately need it — and then...
Git stash is one of those commands that feels minor until the day you desperately need it — and then it becomes indispensable. It lets you temporarily shelve changes you've made to your working directory so you can switch context, pull updates, or work on something else, then come back and reapply those changes later.
When you stash your work, Git takes all your uncommitted changes (both staged and unstaged) and saves them onto a stack of unfinished changes that you can reapply at any time. Your working directory is then cleaned up to match the HEAD commit.
Think of it like putting your work in a drawer so you can clean your desk — the work isn't gone, it's just tucked away.
git stash
This stashes all tracked, modified files. Your working directory reverts to a clean state.
git stash push -m "WIP: refactoring auth middleware"
Always recommended. When you have multiple stashes, messages make it easy to identify which stash contains what.
By default, git stash ignores untracked (new) files. Use -u to include them:
git stash push -u -m "feature work including new files"
To also include ignored files (e.g. .env overrides), use -a:
git stash push -a -m "everything including ignored files"
git stash list
Output looks like this:
stash@{0}: On main: WIP: refactoring auth middleware
stash@{1}: On feature/login: half-done login form
stash@{2}: WIP on main: 3f1abc2 fix typo in readme
Stashes are indexed from 0 (most recent) upward. The index is important for targeting specific stashes.
git stash apply
git stash pop
pop is shorthand for apply + drop. Use it when you're done with the stash and don't need it anymore.
git stash apply stash@{2}
git stash pop stash@{1}
You can apply a stash to any branch — just switch to it first:
git checkout feature/new-branch
git stash pop
Before applying, you might want to see what's inside a stash:
# Summary of changed files
git stash show stash@{0}
# Full diff
git stash show -p stash@{0}
git stash drop stash@{1}
git stash clear
Warning:
git stash clearis irreversible. All stashes are permanently deleted.
If your stashed changes have grown into something bigger, you can create a new branch directly from the stash:
git stash branch feature/new-feature stash@{0}
This creates and checks out a new branch, applies the stash to it, and drops the stash if the apply succeeds. Very handy when you realize mid-stash that your changes deserve their own branch.
You can stash only specific files instead of everything:
git stash push -m "only stashing config changes" -- config/settings.py
Or stash changes interactively (patch by patch, like git add -p):
git stash push -p
Git will walk you through each hunk and ask whether to stash it.
If applying a stash causes a merge conflict, Git will mark the conflicts in the affected files — just like a regular merge. Resolve them manually, then stage the resolved files:
git add path/to/resolved-file.py
Note: when conflicts occur during git stash pop, the stash is not automatically dropped. You'll need to drop it manually once you're done:
git stash drop stash@{0}
| Command | Description |
|---|---|
git stash |
Stash tracked changes |
git stash push -u -m "msg" |
Stash including untracked files with a message |
git stash list |
List all stashes |
git stash show -p stash@{n} |
Show full diff of a stash |
git stash apply stash@{n} |
Apply a stash (keep in list) |
git stash pop |
Apply most recent stash and remove it |
git stash drop stash@{n} |
Delete a specific stash |
git stash clear |
Delete all stashes |
git stash branch <name> |
Create a branch from a stash |
git stash push -p |
Interactive/partial stash |
git stash apply --index to explicitly restore that state.stash@{3}: WIP on main: 9b2f1a0 update readme tells you very little compared to stash@{3}: On main: WIP: OAuth token refresh logic.