How can I use a custom name with git stash to save and retrieve a stash without relying on the stash index?

I want to stash my changes in Git using a custom label so I can retrieve them easily later without having to remember the index. I tried:

git stash save “my_stash_name” But I learned that this only sets a description—it doesn’t let me apply the stash using the name directly. When I run:

git apply my_stash_name

I get an error. Is there a way to use git stash name functionality to both save and reapply a stash by its name rather than index? Any clean solution or workaround would be helpful!

I’ve been working with Git for quite a few years, and I totally get the frustration around using a git stash name directly. You’re right that git stash save "my_stash_name" only sets a description, not an actual retrievable name for commands like git apply.

The cleanest workaround I’ve found is to list your stashes and look for your stash description. For example:

git stash list

You’ll see something like stash@{2}: On main: my_stash_name. You can then apply it using:

git stash apply stash@{2}

If the list is long, I usually combine it with grep:

git stash list | grep my_stash_name

It’s not perfect, but it’s the simplest way I’ve found to retrieve a stash based on the git stash name when the index keeps shifting around.

Nice one, @dipen-soni. I’ve hit the same wall a few times in my own projects. I’ve found that if you want to completely avoid dealing with the stash index and still tie things to your git stash name, a cool trick is to create a new branch straight from the stash.

You can do it like this:

git stash branch my-stash-branch stash@{0}

This creates a new branch with all your stashed changes applied, giving you a clean working area and a proper spot in your Git history. You could even name the branch after your git stash name for easy tracking. The best part? No more worrying about stash indices shifting around — your changes stay safely on that branch until you’re ready to merge or delete it.

Totally agree with you both. Having worked on larger codebases, I found myself wanting something more automated around the whole git stash name issue, especially when juggling multiple stashes.

What’s worked for me is creating a custom alias in my .gitconfig to search the stash list by description and return just the stash reference. Here’s how I set it up:

[alias]  
  stash-name = "!f() { git stash list | grep \"$1\" | cut -d: -f1; }; f"

Then, applying a stash becomes a breeze:

git apply $(git stash-name "my_stash_name")

It’s not quite native support for applying by git stash name, but it feels pretty close and makes scripting or frequent stash juggling much simpler. Super handy if you’re managing lots of stashes with descriptive names.