Stashing Changes
Save uncommitted changes temporarily with git stash.
Why Stash?
Stash is useful when you need to:
- Switch branches with uncommitted work
- Pull changes without committing current work
- Temporarily set aside changes
Basic Stash
Stash Commands
| Command | Description |
|---|---|
git stash | Save changes |
git stash pop | Apply and remove |
git stash apply | Apply but keep |
git stash list | Show all stashes |
git stash drop | Delete a stash |
git stash clear | Delete all stashes |
Saving Changes
Basic Stash
git stash
Stash with Message
git stash push -m "Work in progress on login"
Include Untracked Files
git stash -u
# or
git stash --include-untracked
Retrieving Changes
Apply and Remove
git stash pop
Apply but Keep Stash
git stash apply
Apply Specific Stash
git stash apply stash@{2}
Viewing Stashes
List All Stashes
git stash list
Output:
stash@{0}: WIP on main: abc1234 Last commit message
stash@{1}: On feature: def5678 Another message
Show Stash Contents
git stash show
git stash show -p # With diff
Managing Stashes
Delete Specific Stash
git stash drop stash@{1}
Delete All Stashes
git stash clear
Stash to Branch
Create a branch from stash:
git stash branch new-feature
Exercise: Stash and Pop
Stash current changes, then pop them back:

