How do I name and retrieve a Git stash by name?

To save a stash with a message:

git stash push -m "my_stash_name"

Alternatively (deprecated since v2.16):

git stash save "my_stash_name"

To list stashes:

git stash list

All the stashes are stored in a stack.


To pop (i.e. apply and drop) the nth stash:

git stash pop stash@{n}

To pop (i.e. apply and drop) a stash by name is not possible with git stash pop (see footnote-1).


To apply the nth stash:

git stash apply stash@{n}

To apply a stash by name:

git stash apply stash^{/my_stash_name}

footnote-1:

  • See the man git-stash section regarding apply:

    Unlike pop, may be any commit that looks like a commit created by stash push or stash create.

  • Possible workaround (tested on git version 2.27 and 2.31):

    git stash pop $(git stash list --pretty='%gd %s'|grep "my_stash_name"|head -1|gawk '{print $1}')

Leave a Comment