Mastering Git Stash Drop, Clear, and Untracked Files

You are actively coding a new chat feature when suddenly you need to switch to another branch. Git Stash comes to the rescue, but what happens when you want to delete old stashes or include untracked files? In this guide, we’ll explore how to drop stashes, stash untracked files, and clear the stash stack completely.


Removing a Stash Entry

If you have already applied or popped a stash, you might still see it in the stash list. Let’s check:

git stash list
# stash@{0}: On feature_chat: WIP changes

To delete that stash reference:

git stash drop stash@{0}
# Dropped stash@{0} (WIP changes)

Now your stash list is cleaner.


Adding Untracked Files to Stash

By default, Git only stashes tracked files. Let’s say we create a new file:

echo "few files added in chat feature" > new_chat.txt

git status -s
#  M chat.txt
# ?? new_chat.txt

Notice that chat.txt is modified (tracked), but new_chat.txt is untracked. If we stash normally:

git stash push -m "chat feature edits"

Only chat.txt is saved in the stash. new_chat.txt is still untracked.

To include all files (tracked + untracked):

git stash push -a -m "second stash with all files"

Now both files are stashed.

Check with:

git stash list
# stash@{0}: On feature_chat: second stash with all files
# stash@{1}: On feature_chat: chat feature edits

Clearing All Stashes

If you no longer need any stashes and want to reset everything:

git stash clear

After this, your stash stack will be empty:

git stash list
# (no stash entries found)

Summary

  • git stash drop stash@{0} — delete a specific stash.
  • git stash push -a -m "..." — stash tracked + untracked files.
  • git stash clear — delete all stashes at once.
  • Dangling commits are cleaned up automatically by Git’s garbage collector.

Keep Learning 🚀

👉 Subscribe to Learning Ocean – Subscribers get coupon codes for my courses, early access to blogs and courses, and even exclusive YouTube videos.

👉 My YouTube Channel – More videos, more fun, and lots of learning!

👉 📺 Watch this topic in video form

Stay curious, keep coding, and let’s make learning fun together! 🎉