Learn why the command git stash drop is useful
Need to clear the stash list and donât know how? Donât worry, in this pro tip you will learn how to âthrow awayâ stashes that you no longer need using the command git stash drop
. đ
The usual git stash workflow
Usually, you probably use git stash to store changes that are temporary and not yet ready for a commit. This often happens when you need to interrupt work to fix a bug or something similar on another branch. So your workflow should look like this:
# work work work
git stash
# switch branches and do other deliveries
# go back to the initial branch
git stash pop
So far so good, but what happens when you store changes for another reason, like cleaning up the work environment? Eventually youâll want to get rid of these changes to keep your work environment clean, right? This is where git stash drop
comes in.
Discarding a stash
Old stashes can be a source of a lot of headache, yes conflicts, Iâm talking about you, so itâs important to keep your stash list up to date. Suppose you currently have the following stash list:
You want to get rid of stash number 0
which contains the creation of arquivo-2.txt
. To do this, run the following command:
git stash drop stash@{0}
You should see a message informing the stash has been removed:
Then you can double check the stash listing:
Itâs worth mentioning that just like git stash pop
, if you donât pass the stash name to the command git stash drop
, it will remove the most recent stash from the stack.
GitFichas | GitStudyCards
Hope these commands help you to remove stashes when needed.