Git Stash Command Examples

git stash temporarily shelves (stashes) uncommitted changes so you can switch context — fix a bug, pull updates, or review another branch — and then come back and reapply your work. It is the cleanest way to handle mid-work interruptions without creating WIP commits.

GitStashVersion ControlCLI
Saving Changes
Stash all uncommitted changes
git stash
Stashes both staged and unstaged tracked file changes. Your working directory is reset to match the last commit. Untracked (new) files are not stashed by default — use git stash push -u to include them.
Stash with a descriptive message
git stash push -m "WIP: add user auth middleware"
The -m flag adds a description to the stash entry. This makes it much easier to identify specific stashes when you have multiple saved. Always add messages when you expect to have the stash for more than a few minutes.
Stash including untracked files
git stash push -u
The -u (or --include-untracked) flag also stashes new files that aren't yet tracked by git. Without this flag, untracked files stay in your working directory even after stashing.
List all stash entries
git stash list
Shows all stash entries with their index, branch, and message. Entries are numbered starting at 0 (most recent). The format is stash@{0}: On branch: message. Use this to find the index of a specific stash before applying it.
Applying Changes
Apply and remove the latest stash
git stash pop
Applies the most recent stash entry and removes it from the stash list. This is the most common way to restore stashed work. If there are conflicts, they must be resolved manually before the stash entry is removed.
Apply a specific stash without removing it
git stash apply stash@{2}
apply restores the stash but keeps the entry in the stash list, unlike pop. Specify a stash index from git stash list. Useful when you want to apply the same stash to multiple branches.
Show the diff of a stash entry
git stash show -p stash@{0}
The -p flag shows the full diff of the stash. Without it, only a summary of changed files is shown. Use this to review what is in a stash before applying it, especially if you have multiple stashes with similar messages.
Managing Stashes
Create a branch from a stash
git stash branch feature/my-work stash@{0}
Creates a new branch from the commit the stash was created on, applies the stash, and drops the stash entry. This is the cleanest way to convert stashed work into a proper feature branch when the stash applies with conflicts on the current branch.
Drop a specific stash entry
git stash drop stash@{1}
Permanently removes a specific stash entry without applying it. Use this to clean up stash entries you no longer need. Double-check with git stash show -p stash@{1} before dropping to make sure you don't need the changes.
Clear all stash entries
git stash clear
Removes all stash entries permanently. This action cannot be undone — the stashed changes are gone forever. Use with caution. Review stash list contents with git stash list before clearing.

How to Use

  1. Run git stash to save current changes and get a clean working directory.
  2. Switch branches or pull updates, then return to your branch.
  3. Run git stash pop to restore your changes and remove the stash entry.
  4. Use git stash push -m "message" to add a descriptive label when stashing.
  5. Run git stash list to see all saved stashes and manage them.

Frequently Asked Questions

What is the difference between git stash pop and git stash apply?

git stash pop applies the stash and removes it from the stash list in one step. git stash apply restores the changes but keeps the entry in the stash list. Use apply when you want to apply the same stash to multiple branches or keep it as a backup.

Can I stash only specific files?

Yes, use git stash push path/to/file to stash only specific files. You can also use git stash push -p for interactive (patch) mode, which lets you choose which hunks to stash. This is useful when you have mixed changes and only want to set aside part of them.

Does git stash affect untracked files?

By default, git stash only stashes changes to tracked files (modified and staged). New untracked files are left in the working directory. Add the -u flag (git stash push -u) to include untracked files, or -a to also include gitignored files.

Related Tools