Git Stash

Learn how to temporarily save changes with git stash

Git stash temporarily saves your uncommitted changes so you can work on something else, then come back and re-apply them later.

Basic Commands

# Save current changes to stash
git stash

# Apply most recent stash
git stash pop

# List all stashes
git stash list

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

Common Use Cases

Switch Branches Quickly

# Working on feature, need to switch to main
git stash
git checkout main
# Fix urgent bug
git checkout feature-branch
git stash pop

Save Work in Progress

# Save incomplete work
git stash save "Work in progress on login feature"

# Continue later
git stash apply

Stash Commands

Save Stash

# Simple stash
git stash

# Stash with message
git stash save "Description of changes"

# Include untracked files
git stash -u

# Include ignored files
git stash -a

Apply Stash

# Apply and remove from stash list
git stash pop

# Apply but keep in stash list
git stash apply

# Apply specific stash
git stash apply stash@{1}

Manage Stashes

# List stashes
git stash list

# Show stash content
git stash show stash@{0}

# Delete specific stash
git stash drop stash@{1}

# Clear all stashes
git stash clear

Advanced Usage

Partial Stash

# Stash only staged changes
git stash --staged

# Interactive stash
git stash -p

Create Branch from Stash

# Create new branch with stashed changes
git stash branch new-feature-branch stash@{1}

Free Resources