Summary - Stash
- Git course
- Intermediate
- Lesson 20/82
- 5 min
Combine the stash flow to manage intermediate changes.
Stash workflow summary
git stash provides a clean working directory by safely shelving unfinished work into a stack. You can track all saved stashes and their indexes with git stash list. When restoring, choose pop to discard the entry or apply to keep it for reuse.
git stash push -m "feature work"
git stash list
git stash apply stash@{0}
git stash drop stash@{0}This toolkit lets you manage in-progress work without cluttering commits when switching branches.
Practice Verify stash apply and list
Apply the stash using git stash apply -q, print the file content with cat site.txt, and show that the entry remains in the stack with git stash list.
Starter code
git init -q -b main
git config user.name "Kemal"
git config user.email "kemal@example.com"
echo "ana icerik" > site.txt
git add site.txt
git commit -qm "Ilk site"
echo "yeni banner" >> site.txt
git stash push -qm "banner calismasi"
# Stash'i apply ile uygula, dosya icerigini ve listeyi basSample solution
git init -q -b main
git config user.name "Kemal"
git config user.email "kemal@example.com"
echo "ana icerik" > site.txt
git add site.txt
git commit -qm "Ilk site"
echo "yeni banner" >> site.txt
git stash push -qm "banner calismasi"
git stash apply -q
cat site.txt
git stash listExpected output
ana icerik
yeni banner
stash@{0}: On main: banner calismasi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which stash command should a developer choose to apply the same temporary change to multiple branches?
- git stash clear
- git stash drop
- git stash pop
- git stash apply Correct answer
Explanation: Because git stash apply restores changes without removing the entry, the same stash can be reapplied on another branch.
2 Clear entire stash stack
git stash ____
git stash clear
Explanation: The git stash clear command permanently deletes all stash entries in the stack.
3 Stash workflow matching
| Term | Meaning |
|---|---|
git stash push |
Saves changes with a new message |
stash@{n} |
A specific stash index in the stack |
Tekrar kullanım |
Same stash remains after apply |
Tam temizlik |
clear empties the entire stack |