0
0
Gitdevops~5 mins

Dropping and clearing stashes in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you save changes temporarily in git using stashes. When you no longer need these saved changes, you can remove them to keep your workspace clean.
When you saved changes with git stash but decided you don't need them anymore.
When your stash list is full of old stashes that clutter your project.
When you want to remove a specific stash after applying it successfully.
When you want to clear all stashes to start fresh.
When you want to avoid confusion by deleting unused saved changes.
Commands
This command shows all the saved stashes so you can see what you have before deleting any.
Terminal
git stash list
Expected OutputExpected
stash@{0}: WIP on main: 123abc4 Fix header layout stash@{1}: WIP on main: 789def0 Add login button
This command deletes the specific stash identified by stash@{1} to remove unwanted saved changes.
Terminal
git stash drop stash@{1}
Expected OutputExpected
Dropped stash@{1} (WIP on main: 789def0 Add login button)
This command removes all stashes at once, cleaning up your stash list completely.
Terminal
git stash clear
Expected OutputExpected
No output (command runs silently)
Check the stash list again to confirm the stashes were removed.
Terminal
git stash list
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else from this pattern, remember: use 'git stash drop' to remove one stash and 'git stash clear' to remove all stashes.

Common Mistakes
Trying to drop a stash without specifying the stash name or index.
Git will not know which stash to delete and will show an error.
Always specify the stash to drop, like 'git stash drop stash@{0}'.
Using 'git stash clear' without checking what stashes exist.
You might delete stashes you still need, losing saved work.
Run 'git stash list' first to review stashes before clearing all.
Summary
Use 'git stash list' to see all saved stashes.
Use 'git stash drop stash@{n}' to delete a specific stash.
Use 'git stash clear' to remove all stashes at once.