Git stash is underrated

Ashish Mishra
2 min readApr 5, 2020
Why did i choose this picture ? Let’s find out.

You must have come across the scenario where you have to switch context from your current work and you are in middle of some changes and you can’t commit, that’s where git stash command comes to rescue.

git stash enables temporary storage for your changes in working copy, which can be applied later.

One caveat with git stash is, git won’t stash changes made to untracked or ignored files. git stash -u will add untracked files, and git stash -a will add ignored files as well.

Stashed changes can be applied using—
1. git stash pop — Adds changes back to working copy, and deletes the stash from storage.
2. git stash apply — Works same except it doesn’t delete the stash.(can be useful when you want to apply same stash to multiple branches)

We can also create multiple stashes, hence stash storage can store multiple stashes (hence the image :D), now how to manage multiple stashes —

First of all you can see all current stashes using git stash list

Here you can see current list of stashes each having an unique identifier.
By default, git stash pop or git stash apply will re-apply the most recently created stash: stash@{0}

You can choose which stash to re-apply by passing its identifier as the last argument, for example to apply current last stash using git stash pop stash@{2}

One more interesting thing about stashes, you can also create partial stash using git stash -p, it will ask which files to add in stash, isn’t it amazing?

--

--

Ashish Mishra

I write code, I write words, sometimes both. Platform Engineer@Gojek Ex - Zeta |smallcase | FusionCharts