Delete a Git Stash

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In Git, a stash is a way to save changes that are not yet ready to be committed. Stashes are useful when you need to switch to a different branch or work on a different task, but you don't want to commit your changes yet. However, sometimes you may need to delete a stash that is no longer needed. In this lab, you will learn how to delete a specific stash in Git.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/DataManagementGroup(["`Data Management`"]) git/DataManagementGroup -.-> git/stash("`Save Changes Temporarily`") subgraph Lab Skills git/stash -.-> lab-12724{{"`Delete a Git Stash`"}} end

Delete a Git Stash

You have a Git repository named https://github.com/labex-labs/git-playground. You have created a stash using the command git stash save "my stash". Now, you want to delete this stash because you no longer need it.

  1. Change to the repository directory using the command cd git-playground.
  2. List all stashes using the command git stash list. You should see the stash you just created.
  3. Delete the stash using the command git stash drop stash@{0}.
  4. List all stashes again using the command git stash list.

The stash you just deleted should no longer be there.

Summary

To delete a specific stash in Git, you can use the command git stash drop <stash>, where <stash> is the name of the stash you want to delete. In this lab, you learned how to delete a stash in Git using a specific example.

Other Git Tutorials you may like