Temporarily Storing Changes
Stash saves your uncommitted changes temporarily, letting you switch contexts without committing half-finished work.
Basic Stash
git stashSaves all tracked changes and reverts working directory to last commit.
Stash with Message
git stash save "Work in progress on sensors"Include Untracked Files
git stash -uList Stashes
git stash listOutput:
stash@{0}: WIP on main: abc123 Latest commit
stash@{1}: On feature: Work in progress on sensors
Apply Stash
git stash apply # Apply most recent
git stash apply stash@{1} # Apply specific stashKeeps stash in list after applying.
Pop Stash
git stash popApplies and removes stash from list.
Drop Stash
git stash drop stash@{0}Clear All Stashes
git stash clearView Stash Contents
git stash show -p stash@{0}Common Use Cases
- Switching branches with uncommitted changes
- Pulling latest changes without committing
- Trying different approaches
- Handling urgent bugs mid-feature
Workflow Example
# Working on feature
git stash
# Switch to fix urgent bug
git switch main
# Fix bug, commit, push
# Return to feature
git switch feature-branch
git stash popNext: Quick Commands
Stash is your temporary storage. Next, learn aliases to speed up your workflow with custom shortcuts.