This site runs best with JavaScript enabled.

GIT Stash

Kevin Beck

August 27, 2019

So I always used GIT stash when I had been working on a bug and getting no where then needed to quickly get back to the root branch or a previous commit. Code would be stashed and forgotten about... I now know the better usage of GIT stash.

For the times you are not ready to commit any changes but need to work on another bug.

git stash

"In its simplest form, the git stash command creates a stash entry.

To reapply our stashed changes at a later point, we can use git stash apply.

We can apply the stash entry to a different branch – it doesn’t have to be the branch that we created the stash from."

Multiple stash entries with a custom message

git stash save 'custom message'

Then to list all stash entries

git stash list
stash@{0}: On my-branch: custom message
stash@{1}: On my-branch: custom message, again
stash@{2}: On my-branch: again with the custom message

You can then apply a previous stash

git stash apply stash@{2}

"Subsequent stash entries are added to the beginning of the stash list. The most recent stash will have the reference stash@{0}.

If we want to remove a stash entry from the list when we apply it, we could use pop instead of apply."

Removing and clearing stashes

Removing all stash entries:

git stash clear

Or removing individual stash entries:

git stash drop stash@{2}