Save your work temporarily without committing — switch tasks instantly.
git stash lets you:
Save uncommitted changes temporarily and clean your working directory.
Scenario:
You are working on Feature A
→ Suddenly urgent bug appears
→ You need to switch branch
Without stash: ❌ messy commits ❌ lost changes
With stash: ✅ safe temporary storage ✅ clean working directory
flowchart LR
A[Working Directory Changes] --> B[git stash]
B --> C[Saved in Stash Stack]
C --> D[Apply Later]
git stashgit stash listExample:
stash@{0}: WIP on main
stash@{1}: WIP on feature
git stash applygit stash popgit stash drop stash@{0}When you run:
git stashGit:
1. saves changes as a commit (hidden)
2. stores in stash stack
3. resets working directory
stash = commit object (not branch)
refs/stash → points to latest stash
Working Directory
↓ stash
Stash Stack
↓ apply/pop
Working Directory
1. Working on login feature
2. Urgent bug arrives
3. git stash
4. switch branch
5. fix bug
6. return to feature
7. git stash pop
git stash push -m "login feature work"git stash push file1.jsgit stash -ugit stash apply stash@{1}Stack behavior (LIFO)
stash@{0} → latest
stash@{1} → older
Sometimes:
git stash popcan cause conflicts.
# resolve conflicts
git add .
git commit| Stash | Commit |
|---|---|
| temporary | permanent |
| not in history | part of history |
| quick save | structured save |
Use:
git stash listNot recommended.
Always add messages.
- use stash for short-term work
- name your stashes
- clean old stashes
- don’t rely on stash for important work
Temporary storage for uncommitted changes.
In a special ref called refs/stash.
Apply keeps stash, pop removes it.
Yes, with -u.
# create changes
echo "test" >> file.txt
# stash
git stash
# switch branch
git checkout main
# come back
git checkout -
# apply stash
git stash popGit stash is a productivity superpower.
Use it when:
- switching tasks
- handling interruptions
- keeping work safe without committing
➡️ 02-git-cherry-pick.md