Stashing in Git
This article belongs to the Git Basics to Advanced course, which is currently being revisited with updated architectural patterns and content. Content may be refined shortly.
Stashing allows you to save uncommitted changes temporarily and restore them later. This is useful when you are interrupted and need to switch tasks or branches without committing half-finished work.
1. Basic Stashing Workflow
[do some work]
[get interrupted]
git stash
[deal with interruption]
git stash pop
Example Scenario
Consider being in the following state with uncommitted modifications:



When an urgent bug fix interrupts your feature work, shelve your uncommitted work with git stash:
git stash
git status
git log --graph --all --oneline

Git creates a special stash commit holding your working tree and staging state, resetting your working tree back to HEAD:

After handling the urgent task, pop your changes back:
git stash pop
2. Interactive Stash Explorer
Step through the interactive visualizer below to see how edits move into the stash stack and how the working tree is cleanly restored:
Git Stash Lifecycle
Step 1 of 3: Dirty Working Tree InterruptionActive workspace where files are created & edited.
Prepared files staged via git add.
Immutable snapshots created via git commit.
$ git status You have unfinished edits in app.js and new-form.html when an urgent task arrives.
3. Managing Multiple Stashes
Git keeps multiple stashes in a LIFO (Last-In, First-Out) stack:
# List all saved stashes
git stash list
# Inspect what changes are inside a stash:
git stash show --patch stash@{0}
git stash show --patch stash@{1}
Managing Multiple Stashes (LIFO Stack)
Step 1 of 4: Save First Feature to StashActive workspace where files are created & edited.
Prepared files staged via git add.
Immutable snapshots created via git commit.
$ git stash save "WIP auth" First set of unfinished edits is saved to stash@{0}. Working directory is clean.
Applying vs Popping
git stash pop: Reapplies the most recent stash (stash@{0}) and removes it from the stack.git stash apply stash@{1}: Reapplies a specific stash but keeps it on the stack.
4. Deleting Stashes
# Drop a specific stash
git stash drop stash@{0}
# Remove all stashes completely
git stash clear
5. Stashing Untracked Files
By default, git stash only stores tracked files. To include untracked new files, use -u:
# Include untracked files
git stash -u
# Include all files, including those in .gitignore
git stash --all