Read Anthropic’s case study about Graphite Reviewer

How to delete stashes in Git

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Deleting stashes can help keep your repository clean and manageable, especially in a busy development environment. This guide will walk you through the process of deleting stashes in Git, covering how to delete a specific stash, the last stash, and all stashes.

Before explaining how to delete stashes, it's important to understand what a stash is. In Git, a stash is a temporary storage for uncommitted changes that you want to save without committing them to the repository's history. It allows you to switch branches without committing incomplete work.

If you want to delete a specific stash from the stash list, you first need to identify it. Use the following command to list all stashes with their indices:

Terminal
git stash list

Each entry in the stash list is prefixed with stash@{index}, where index is a number identifying the position of the stash in the stash stack. The most recently created stash has the index 0.

To delete a specific stash, use:

Terminal
git stash drop stash@{index}

Replace {index} with the number of the stash you want to delete. For example, if you want to delete the third stash in the list:

Terminal
git stash drop stash@{2}

The last stash is always stash@{0}. If you want to delete the most recently created stash, you can use:

Terminal
git stash drop stash@{0}

Or simply:

Terminal
git stash drop

This command, without any arguments, defaults to deleting the last stash.

If you decide to clean up all stashed changes, Git provides a straightforward command to clear the entire stash list:

Terminal
git stash clear

This command will remove all stashes and is irreversible, so make sure that you no longer need any of the stashed changes before executing it.

  • Review before deleting: Always review the contents of a stash before deleting it to ensure that you are not losing important work. You can inspect the contents of a stash by using:

    Terminal
    git stash show -p stash@{index}

    Add the -p option to show the actual changes in patch form.

  • Backup stashes: If you are unsure about deleting a stash but want to clean up, consider applying the stash to a new branch where you can commit the changes permanently:

    Terminal
    git stash branch new-branch-name stash@{index}

    This creates a new branch with the stashed changes applied, allowing you to review them in isolation.

For further reading see this guide on how to use the Git stash command.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2