If your Git stash list has become cluttered, you can remove one saved change or clear every stash entry at once. The quickest way to clear the entire list is to run git stash clear from the repository where the stashes were created. If you only want to remove a particular entry, use git stash drop instead. Because clearing stashes can permanently remove work you have not committed, check the list and confirm you no longer need the saved changes before proceeding.
How Do I Clear the Git Stash List?
To remove every entry from the stash list in the current Git repository, run:
git stash clear
This deletes all stash entries for that repository. It does not delete your repository, branches, or committed history, and it does not clear stashes belonging to other repositories. However, it does remove the saved changes represented by the stash entries, so use it only when you are sure you no longer need them.
To check the list before clearing it, run:
git stash list
A stash list might look like this:
stash@{0}: WIP on main: 8a4c21d Update navigation
stash@{1}: On feature/search: Add search styles
stash@{2}: WIP on main: 3f9b701 Fix form validation
After running git stash clear, run git stash list again. If there are no stash entries, Git prints no list items.
What Does git stash clear Do?
Git stash stores changes that are not ready to be committed, letting you switch tasks and return to those changes later. Each saved set of changes appears as an entry in the stash list. The command git stash clear removes all of those entries from the list for the current repository.
Clearing the list is different from deleting a branch or resetting your working tree. The command does not change your current branch or remove files from a commit. Its effect is specifically to remove the saved stash entries. Once removed, the changes in those stashes are no longer available through the normal stash commands.
Git may eventually prune the underlying objects after they become unreachable. That means recovery can be difficult or impossible, especially after Git’s maintenance or garbage-collection processes run. Treat git stash clear as a destructive operation rather than a temporary way to hide entries.
How to Remove One Stash Instead of Clearing the List
If you want to keep some stashes and delete only one, use git stash drop. First display the entries:
git stash list
Then specify the entry you want to remove. For example, to delete the newest stash:
git stash drop 'stash@{0}'
To remove the second entry in the list, use:
git stash drop 'stash@{1}'
Quotation marks around a stash reference can help avoid shell interpretation issues, particularly in shells that treat curly braces specially. You can also use the shorter command when you intend to drop the latest entry:
git stash drop
Stash numbers can change after you remove an entry. For instance, after dropping stash@{0}, the old stash@{1} may become the new stash@{0}. Check git stash list again before removing another numbered stash.
How to Apply or Save a Stash Before Removing It
If you are unsure whether a stash contains useful work, inspect it before deleting it. To view a summary of changes in the newest stash, run:
git stash show 'stash@{0}'
To see the full patch, add the --patch option:
git stash show --patch 'stash@{0}'
You can apply a stash to your working tree without removing it from the list:
git stash apply 'stash@{0}'
When you are ready to apply the newest stash and remove it if the operation succeeds, use:
git stash pop
In general, git stash apply keeps the stash entry, while git stash pop applies it and then removes it when it can do so successfully. If applying the changes causes conflicts, Git may keep the stash so you can resolve the conflicts without losing the saved entry. Check the command output and your working tree before deciding what to do next.
If you want to preserve a stash independently of the stash list, you can create a branch from it:
git stash branch review-saved-work 'stash@{0}'
This creates and checks out a branch based on the commit where the stash was originally made, then applies the stashed changes. It can be useful when a stash conflicts with your current branch or when you want to review the changes separately. Confirm that the branch contains the work you need before clearing the remaining stash entries.
Clear All Stashes Safely: A Step-by-Step Checklist
Before clearing your Git stash list, follow these checks to reduce the chance of deleting work you still need:
-
Confirm the repository: Run
git statusand make sure you are in the intended project directory. -
Review the stash list: Run
git stash listand note how many entries exist. -
Inspect uncertain entries: Use
git stash showorgit stash show --patchto check what a stash contains. - Preserve useful changes: Apply, branch from, or otherwise save any stash you may need later.
-
Clear the list: Run
git stash clearonly when you are ready to remove every entry. -
Verify the result: Run
git stash listagain to confirm the list is empty.
For example, a cautious check might look like this:
git status
git stash list
git stash show --patch 'stash@{0}'
git stash clear
git stash list
Do not copy and run the full sequence blindly if you have not reviewed the stashes. The inspection commands are there to help you make an informed decision before the destructive command.
Can You Undo git stash clear?
There is no standard git stash undo command. After git stash clear, the entries no longer appear in git stash list, and Git may eventually delete the unreachable objects that held their changes. If you cleared the list by mistake, avoid running cleanup commands such as git gc while you investigate, because cleanup can make any remaining recovery opportunity disappear.
In some cases, an experienced Git user may be able to search for unreachable commits with commands such as git fsck. However, this is not a dependable recovery method, and it may require identifying the right commit and reconstructing the changes manually. If the stashed work is important, first check for another copy in a branch, patch file, backup, IDE history, or another developer’s clone. Prevention—reviewing and saving stashes before clearing them—is much more reliable than recovery.
Common Questions About Clearing a Git Stash List
Does git stash clear delete my current uncommitted changes? No. It removes stash entries; it is not a command for deleting the changes currently in your working tree. Still, check git status so you understand which changes are in your working tree and which are saved in stashes.
Does git stash clear affect every repository? No. It affects the stash list for the repository in which you run the command. Change to another repository and its stash list remains separate.
How do I delete all Git stashes from the command line? Run git stash clear in the correct repository. Verify the result with git stash list.
How do I delete the latest stash only? Run git stash drop, or specify git stash drop 'stash@{0}'. The first entry, stash@{0}, is normally the newest stash.
Should I use git stash clear or git stash drop? Use git stash clear when you intend to remove every stash entry. Use git stash drop when you want to remove one entry and keep the others.
Conclusion
To clear your entire Git stash list, run git stash clear from the repository that contains those stashes. Review the entries with git stash list first, because clearing them removes your normal access to all saved stash changes and recovery is not guaranteed. If you only want to delete a single entry, use git stash drop; if you may need the changes later, inspect and apply them or create a branch before removing anything.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.