How to Remove Git Stash Entries?

Remove a Specific Git Stash

You can remove a git stash using the git stash drop command. It has the following syntax (where n is the stash index):

git stash drop stash@{n}

For example, the following would delete stash at index 1:

git stash drop stash@{1}

When you drop stash at index 1, stashes at index 2 and 3, for example, become stashes 1 and 2 respectively. So when you're deleting stashes individually, it might be a good idea to keep a check on the ones you're removing as the indexes are adjusted after each remove.

Determine Which Stash to Delete:

In order to find the stash you wish to delete, you can retrieve a list of all stashes and their respective indexes like so:

git stash list

Each stash entry would be listed like so:

stash@{0}: WIP on your-branch: 4eba0d9... Description...
stash@{1}: On master: 2eb0399... Description...

Or, if you're looking for a particular stash, you can use the grep flag with git stash list like so:

git stash list --grep=your-branch

Inspecting Changes in a Stash:

Before deleting a stash, you might be interested in inspecting the changes in that stash. You can do so using the following command (where n is the stash index):

git stash show stash@{n}

We won't go into much detail about this in this article as it is beyond its scope. You can read up more about it if you feel the need.

Remove All Git Stash Entries

You can remove all git stash entries using the following command:

git stash clear

Use this with caution though, as once the stash entries are removed, it might be impossible to recover.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.