Your Search Bar For Shrewd Tips

How Do I Clear Git Stash?


Git stash is a handy way to set aside uncommitted changes while you switch branches or handle another task. Over time, however, your stash list can fill with old, temporary work. To remove every saved stash in the current repository, run git stash clear. If you only want to delete one entry, use git stash drop instead. This guide explains both options, how to check what is saved, and how to avoid deleting work you still need.

What Does Git Stash Clear Do?

The command git stash clear removes all stash entries from the current Git repository. A stash is a saved set of changes that Git keeps separately from your normal commit history. Stashes are useful for short-term work, but they are not permanent backups or commits.

When you clear the stash, Git removes the references to every stash entry in that repository. Your current working files and committed history are not changed by this command. However, the saved changes in the stash list will no longer be available through normal stash commands. Treat the operation as destructive: do not run it until you are sure you no longer need those changes.

Run the command from any directory inside the repository:

git stash clear

There is no stash name or number to provide. Git clears the entire stash list for the repository, and it does not ask you to confirm first.

How to Check Your Stash List Before Clearing It

Before deleting stashes, review what is saved. The simplest way to list your entries is:

git stash list

Git displays entries with identifiers such as stash@{0} and stash@{1}. The newest entry is generally at the top of the list as stash@{0}. An entry may also include the branch where it was created and a message describing the work.

For example, a list might look like this:

stash@{0}: On feature/search: adjust search results
stash@{1}: On main: unfinished navigation update

To see a summary of the changes in a particular stash, use git stash show with its identifier:

git stash show stash@{0}

To inspect the complete patch, add the -p option:

git stash show -p stash@{0}

Reviewing the list and patch helps you distinguish disposable experiments from work that should be restored, saved, or shared with someone else. If a stash contains changes you may need later, do not clear it just because its message is unclear. Inspect it first, then give it a useful message or preserve it another way.

How to Clear All Git Stashes

Once you have confirmed that none of the entries are needed, clear all stashes by running:

git stash clear

Then verify that the list is empty:

git stash list

If the command succeeds and there are no remaining entries, the list produces no stash lines. You can run git stash clear again if needed; clearing an already empty stash list has nothing further to remove.

Keep in mind that stashes belong to a specific local repository. Clearing the stash in one clone does not clear stashes in a different clone of the same project. Git does not normally push stash entries to a remote when you push branches, so a coworker’s local stash list is separate from yours.

How to Delete Just One Stash

If you want to keep some entries, do not use git stash clear. Remove a single entry with git stash drop followed by its identifier:

git stash drop stash@{0}

This deletes the selected stash rather than the entire list. Check the list again afterward:

git stash list

Stash identifiers are position-based, so the numbers can change when an entry is removed. For example, after dropping stash@{0}, the entry that was previously stash@{1} may become stash@{0}. Always check the current list before dropping another numbered entry. If you are deleting several specific stashes, inspect the list again after each deletion rather than relying on old numbers.

How to Restore a Stash Instead of Deleting It

If you discover that a stash contains work you want to continue, restore it before clearing anything. The two common options are git stash apply and git stash pop.

  • git stash apply stash@{0} applies the changes but keeps the stash entry in the list.
  • git stash pop stash@{0} applies the changes and removes the entry if the operation succeeds.

Applying a stash may produce merge conflicts if the files have changed since the stash was created. In that case, resolve the conflicts and check the resulting files before proceeding. Applying a stash does not automatically commit the changes, so review them and commit when you are ready.

If you want to restore a stash on a new branch, you can use:

git stash branch new-work-branch stash@{0}

This creates a branch based on the commit where the stash was originally made and applies the stash there. It can be useful when the changes no longer apply cleanly to your current branch.

How to Save a Stash Before Clearing It

If you are unsure whether you will need a stash, preserve it before removing it. One straightforward option is to apply the stash, review the changes, and commit them on an appropriate branch. A commit gives the work a place in your project’s history and makes it easier to share or recover later.

You can also export a stash patch to a file. For example, to save the patch for the newest stash:

git stash show -p stash@{0} > saved-changes.patch

Keep the patch somewhere safe and check that it contains the expected changes. A patch can often be applied later with git apply, but it may require adjustments if the project has changed. For a more durable backup, create a branch and commit the work rather than relying only on an exported patch.

Can You Recover a Stash After Git Stash Clear?

In normal use, you should assume that a stash removed by git stash clear is gone. Git may retain underlying objects temporarily until cleanup removes them, so recovery can sometimes be possible with advanced repository inspection. That is not a dependable recovery plan: the objects may be pruned, and finding the right changes can be difficult.

If you accidentally clear your stash, avoid running cleanup or maintenance commands that could remove unreachable objects. Experienced Git users may be able to investigate with commands such as git fsck --no-reflogs --unreachable, then inspect any promising commits or blobs. Results vary, and this process is not guaranteed to restore a complete, usable stash. If the work is important, ask a Git expert for help before making further changes to the repository.

The safest approach is prevention: inspect entries before clearing them, restore or commit valuable work, and keep a separate backup when necessary. Do not use stash as the only long-term storage for important changes.

Common Git Stash Cleanup Mistakes

  • Using clear when you mean drop: git stash clear removes every stash in the current repository. Use git stash drop stash@{n} to remove one.
  • Skipping the review: Run git stash list and inspect relevant changes with git stash show -p before deleting anything.
  • Assuming a stash is backed up remotely: Stashes are local by default and are not included in an ordinary push.
  • Expecting clear to change your working files: Clearing the stash list does not restore its changes or remove unrelated edits from your working directory.
  • Trusting recovery as a safety net: Lost stash data may be difficult or impossible to recover, so make a backup before clearing valuable work.

Quick Reference: Git Stash Commands

  • git stash list — list saved stashes.
  • git stash show stash@{0} — summarize one stash.
  • git stash show -p stash@{0} — display its full patch.
  • git stash apply stash@{0} — apply a stash and keep it in the list.
  • git stash pop stash@{0} — apply a stash and remove it if successful.
  • git stash drop stash@{0} — remove one stash entry.
  • git stash clear — remove all stash entries in the current repository.

Conclusion

To clear every saved stash in a Git repository, run git stash clear. Because the command removes the whole stash list without a confirmation prompt, check your entries first with git stash list and inspect anything uncertain with git stash show -p. If you only need to delete one item, use git stash drop; if you want to keep the work, apply it, commit it, or save a patch before cleaning up. A quick review before clearing can prevent the loss of changes that are difficult to recover.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →