Stash: git stash

Git Tips & Commands

The Git Stash as a place to temporarily store that's not ready to be permanently stored in a commit. Let's say you're working on some code that you're not ready to commit. You get a request to make a change and push the code. What do you do with the other code you've been working on? You can stash it away, do your work, and bring the code back from the stash.

For All the Commands Below

The commands below assume you've navigated to the folder for the Git repo.

Create a Stash

To stash away your uncommitted code for later, run one of these commands:

  • git stash
  • git stash save "A meaningful name/message"
  • NOTE: You can have multiple stashes. You're not required to name each stash, but you may want to give it a meaningful name.

List Stashes

To see a list of your stashes, run this command:

  • git stash list

Restore/Apply a Stash

To apply the latest stash, run this command:

  • git stash pop
    • To apply a specific stash (and remove it from the stash list), run the following command. (Replace stash@{0} with the stash you want to restore, which you find in the list of stashes):
  • git stash pop stash@{0}
    • To apply a specific stash (and keep it in the stash list), run the following command. (Replace stash@{0} with the stash you want to restore, which you find in the list of stashes):
  • git stash apply stash@{0}

Removing Stashes

To deletes all stashes, run this command:

  • git stash clear

To delete a specific stash, run the following command. (Replace stash@{0} with the stash you want to delete, which you find in the list of stashes):

  • git stash drop stash@{0}

Go Beyond Git

We offer a full suite of coding courses. Classes are small, hands-on, and expert-led. Check out our coding bootcamps and schools now:

How to Learn Git

Master Git with hands-on training. Git is a free, open-source version control system that allows developers to track the changes they make to code.

Yelp Facebook LinkedIn YouTube Twitter Instagram