Stashing in Git
git stash→ Save changes temporarilygit stash list→ Show stashed changesgit stash apply→ Reapply stashed changesgit stash drop→ Delete a stashgit stash pop→ Apply & remove stash
git stash
git stash [push] [options] [--] [<pathspec>...]
git stash pop [options] [<stash>]
git stash apply [options] [<stash>]
git stash list
git stash show [<stash>]
git stash drop [<stash>]
git stash clear# Stash all changes (default):
git stash
# Stash with a custom message:
git stash push -m "WIP: login feature"
# Stash only staged changes:
git stash --staged
# Stash including untracked files:
git stash -u
# Stash including ignored files:
git stash -a
# List all stashes:
git stash list
# Show details of a stash:
git stash show -p stash@{0}
# Reapply latest stash and drop it:
git stash pop
# Reapply stash but keep it in stack:
git stash apply stash@{2}
# Delete a stash entry:
git stash drop stash@{1}
# Clear all stashes:
git stash clear- Description: The
git stashtemporarily saves (or “stashes”) your uncommitted changes (both staged and unstaged) so you can work on something else, then reapply them later. - Usage: It saves changes into a stack, lets you switch branches or pull updates safely, and reapply them later.
- Think Tank: Think of it as putting your unfinished work into a drawer - safe, out of the way, but retrievable.
| Option | Description |
|---|---|
-m |
Add a custom message to stash entry |
-u, --include-untracked
|
Stash untracked files as well |
-a, --all |
Stash untracked + ignored files |
--staged |
Stash only staged changes |
--keep-index |
Stash changes but keep staged files intact |
--patch |
Interactively choose hunks to stash |
- Best Practices:
- Always add a message (
-m) to describe the stash for clarity. - Use
git stash listregularly to avoid losing track of multiple stashes. - Prefer
git stash popwhen you’re done with the stash, so it doesn’t clutter the stack. - Use
git stash branchif you realize stashed changes deserve their own branch. - Avoid stashing ignored files unless absolutely necessary.
- Always add a message (
How it works
- Working tree + index snapshot:
git stashtakes the current state of your working directory and staging area, saves it as a new entry in the stash stack, and reverts your working directory to match HEAD (clean state). - Stash stack: Each stash is stored as a commit object in a hidden ref (
refs/stash). You can have multiple stashes, managed like a stack (LIFO). - Reapply later: You can bring back stashed changes with
git stash applyorgit stash pop.
Git - git-reset Documentation


Updated on Dec 23, 2025