Terminal GuideTerminal Guide

git stash Command Guide

Stash the changes in a dirty working directory away

6 min readLast updated: January 19, 2026
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Save

git stashStash changes
git stash -m "msg"Stash with message
git stash -uInclude untracked

Apply

git stash popApply and remove
git stash applyApply and keep
git stash apply stash@{2}Apply specific

Manage

git stash listList all stashes
git stash showShow stash diff
git stash dropDelete stash

Downloadable Image Preview

Failed to generate preview

Basic Usage

The git stash command temporarily saves uncommitted changes, allowing you to switch branches or perform other operations with a clean working directory.

bash
# Stash current changes
git stash

# Stash with a descriptive message
git stash -m "Work in progress on login"

# Apply the most recent stash
git stash pop

Stashing Options

bash
# Basic stash (tracked files only)
git stash

# Include untracked files
git stash -u
git stash --include-untracked

# Include untracked and ignored files
git stash -a
git stash --all

# Stash with message
git stash -m "WIP: feature X"
git stash push -m "WIP: feature X"

# Stash specific files
git stash push -m "Just these files" file1.js file2.js

# Interactive stash (select hunks)
git stash -p

Applying Stashes

bash
# Apply most recent stash and remove it
git stash pop

# Apply most recent stash but keep it
git stash apply

# Apply a specific stash
git stash apply stash@{2}

# Apply and keep the staged state
git stash apply --index

# Create branch from stash
git stash branch new-feature-branch

pop vs apply

  • pop: Apply + remove from stash list (use when done)
  • apply: Apply + keep in list (use when testing)

Managing Stashes

bash
# List all stashes
git stash list
# stash@{0}: WIP on main: abc1234 Last commit msg
# stash@{1}: On feature: def5678 Another commit

# Show stash contents (diff)
git stash show
git stash show -p           # Full diff
git stash show stash@{2}    # Specific stash

# Delete a stash
git stash drop              # Drop most recent
git stash drop stash@{2}    # Drop specific

# Delete all stashes
git stash clear

Practical Examples

bash
# Quick context switch
git stash -m "WIP: feature work"
git checkout hotfix
# ... fix the bug ...
git checkout feature
git stash pop

# Pull with local changes
git stash
git pull
git stash pop

# Move changes to a new branch
git stash
git checkout -b new-feature
git stash pop

# Test changes on another branch
git stash
git checkout other-branch
git stash apply  # Keep stash for main branch
# ... test ...
git stash drop  # Remove when done
git checkout main
git stash pop

# Stash only unstaged changes
git stash --keep-index

Frequently Asked Questions

What is the difference between stash pop and stash apply?

"git stash pop" applies the stash and removes it from the list. "git stash apply" applies but keeps the stash. Use apply if you want to apply the same stash to multiple branches.

How do I stash untracked files?

Use "git stash -u" or "git stash --include-untracked". By default, stash only saves tracked files. Add -a to also include ignored files.

Can I stash just some files?

Yes, use "git stash push -m "message" file1 file2" to stash specific files only. Or use "git stash -p" to interactively select what to stash.

How do I recover a dropped stash?

If you accidentally dropped a stash, use "git fsck --unreachable | grep commit" to find lost commits, then "git stash apply <sha>" to recover.

Can I create a branch from a stash?

Yes! Use "git stash branch <branch-name>" to create a new branch and apply the stash there. This is useful if applying the stash causes conflicts.

Summary

git stash is perfect for temporarily shelving changes. Always use descriptive messages and clean up old stashes regularly.

Quick Reference

  • git stash - Save changes
  • git stash pop - Apply and remove
  • git stash list - List all stashes
  • git stash drop - Delete stash

Official Documentation

For authoritative information, refer to the official documentation:

Related Articles