Lesson 39 of 6815 min read

git stash pop / apply / list / drop: Managing the Stash Stack

Learn how to view, restore, and clean up multiple saved stashes using git stash list, apply, pop, and drop.

Author: CodersNexus

git stash pop / apply / list / drop: Managing the Stash Stack

Once you've stashed some work (previous lesson), you'll eventually want to bring it back — and if you stash more than once before returning to earlier work, you'll need to manage a whole stack of saved stashes. This lesson covers the complete lifecycle: listing what's stashed, restoring a specific stash (in two subtly different ways), and cleaning up stashes you no longer need.

Learning Objectives

  • List all currently saved stashes using git stash list.
  • Restore a stash using git stash pop, and understand how it differs from git stash apply.
  • Apply or pop a specific stash (not just the most recent one) using its stash index.
  • Remove a specific stash with git stash drop, or clear all stashes at once.

Key Terms to Know Before Learning git stash pop / apply / list / drop

  • git stash list: A command that displays every currently saved stash, most recent first, each identified by an index like stash@{0}.
  • git stash pop: Restores the most recent stash's changes into your working directory AND removes it from the stash list.
  • git stash apply: Restores the most recent stash's changes into your working directory, but leaves it in the stash list (does not remove it).
  • git stash drop: Permanently removes a specific stash from the list without applying its changes.
  • git stash clear: Permanently removes all stashes at once.
  • stash@{n}: The index-based identifier used to reference a specific stash other than the most recent one, where {0} is the most recent, {1} the next most recent, and so on.

How git stash pop / apply / list / drop Actually Works

Stashes are stored as a stack, most recent on top, and `git stash list` shows all of them:

```
git stash list
stash@{0}: On feature/login: WIP: refactoring login validation
stash@{1}: On main: WIP on main: 3c4d5e6 Update README
```

Each stash is identified by an index in the form `stash@{n}`, where `{0}` is always the most recently created stash, `{1}` the one before that, and so on.

To bring a stash's changes back into your working directory, you have two closely related but importantly different options:

- `git stash pop` restores the most recent stash's changes (`stash@{0}`) into your working directory **and removes it from the stash list** afterward — as if you're popping it off the top of a stack, consuming it in the process.
- `git stash apply` restores the most recent stash's changes into your working directory but **leaves it in the stash list**, unchanged — useful if you want to apply the same stashed changes to more than one branch, or simply want to keep it around a bit longer as a safety net even after restoring it once.

```
git stash pop # restore AND remove the most recent stash
git stash apply # restore but KEEP the most recent stash in the list
```

Both commands can target a specific stash other than the most recent one, by supplying its index:

```
git stash pop stash@{1}
git stash apply stash@{1}
```

It's worth noting that restoring a stash (via either `pop` or `apply`) can, in principle, result in a conflict — similar in nature to a merge conflict — if the stashed changes overlap with content that has changed in your working directory since the stash was created. If this happens, `pop` will not remove the stash from the list until the conflict is fully resolved, ensuring you don't lose your stashed work due to an incomplete restoration.

Finally, for cleanup: `git stash drop` permanently removes a specific stash from the list *without* applying its changes first — useful once you're certain a stash is no longer needed:

```
git stash drop stash@{1}
```

And `git stash clear` removes every stash at once, a more drastic, permanent operation to use only when you're confident none of your accumulated stashes are needed anymore:

```
git stash clear
```

A sensible default habit for most everyday use: reach for `git stash pop` when you simply want your most recent stashed work back and don't need to keep a copy around — it's the most common operation and keeps your stash list tidy automatically as you go.

git stash pop / apply / list / drop: Visual Walkthrough

Draw a vertical stack of three boxes representing stashes, labeled top to bottom: 'stash@{0}: WIP refactoring login (most recent)', 'stash@{1}: WIP README notes', 'stash@{2}: WIP experimental CSS (oldest)'. Draw two arrows from the top box: one labeled 'git stash pop' showing it being removed from the stack after restoring (stack shrinks to 2), and one labeled 'git stash apply' showing it staying in place after restoring (stack remains 3). Draw a third arrow from the bottom box labeled 'git stash drop stash@{2}' showing it being deleted without restoring anything.

git stash pop / apply / list / drop: Quick Reference Table

CommandRestores Changes?Removes from Stash List?
git stash popYes (most recent, or specified index)Yes — removed after successful restoration
git stash applyYes (most recent, or specified index)No — remains in the list
git stash drop <stash>NoYes — removed without ever restoring it
git stash clearNoYes — removes ALL stashes at once

git stash pop / apply / list / drop: Command Syntax and Examples

# See all currently saved stashes
git stash list
# stash@{0}: On feature/login: WIP: refactoring login validation
# stash@{1}: On main: WIP on main: 3c4d5e6 Update README

# Restore the most recent stash AND remove it from the list
git stash pop

# Restore the most recent stash but KEEP it in the list
git stash apply

# Restore a SPECIFIC older stash by index
git stash pop stash@{1}

# Permanently delete a specific stash without restoring it
git stash drop stash@{1}

# Permanently delete ALL stashes at once
git stash clear

Breaking Down the git stash pop / apply / list / drop Example

`git stash list` shows two saved stashes, with `stash@{0}` being the most recently created. `git stash pop` (with no index) restores and removes that most recent one. `git stash apply` demonstrates the alternative that restores the same changes but deliberately leaves the stash in the list, useful if you might want to apply those same changes elsewhere later. Targeting `stash@{1}` explicitly with either `pop` or `drop` shows how to work with a stash other than the most recent one. Finally, `git stash clear` is presented as the more drastic, all-at-once cleanup option, to be used deliberately once you're confident no remaining stashes are needed.

How git stash pop / apply / list / drop Is Used on Real Engineering Teams

  • Developers who frequently context-switch between multiple in-progress tasks often accumulate several stashes at once, making git stash list and precise index-based pop/apply/drop commands essential daily tools.
  • Some developers deliberately use git stash apply (instead of pop) when they want to test the same set of stashed changes against two different branches, without needing to stash it again for the second attempt.
  • Cleaning up an old, forgotten stash discovered via git stash list is a common 'digital housekeeping' task engineers perform periodically, especially before starting a new project phase.
  • CI/CD or automated environments occasionally use scripted stash management (list, apply by index, drop) as part of complex, multi-step automated workflows involving temporary code modifications.

git stash pop / apply / list / drop Interview Questions and Answers

Q1. What is the difference between git stash pop and git stash apply?

Both restore the stashed changes into your working directory. The key difference is that git stash pop also removes that stash from the stash list afterward (assuming a successful restoration with no unresolved conflicts), while git stash apply leaves the stash in the list, unchanged, allowing you to apply the same changes again later if needed.

Q2. How would you restore a stash that isn't the most recent one?

Use its specific index from git stash list, in the form stash@{n}, for example git stash pop stash@{1} or git stash apply stash@{1}, rather than the default behavior which always targets the most recent stash (stash@{0}).

Q3. What is the difference between git stash drop and git stash clear?

git stash drop removes one specific stash from the list without ever restoring its changes into your working directory. git stash clear is a more drastic operation that removes every stash currently saved, all at once.

git stash pop / apply / list / drop Quiz: Test Your Understanding

1. What is the key difference between git stash pop and git stash apply?

  1. pop restores changes without removing the stash; apply removes the stash without restoring changes
  2. pop restores AND removes the stash; apply restores but keeps the stash in the list
  3. They are identical commands with different names
  4. apply only works on the oldest stash; pop only works on the newest

Answer: B. pop restores AND removes the stash; apply restores but keeps the stash in the list

Explanation: Both commands restore the same stashed changes, but pop additionally removes that stash from the list afterward, while apply deliberately leaves it there for potential reuse.

2. In git stash list output, what does stash@{0} represent?

  1. The oldest saved stash
  2. The most recently created stash
  3. A stash that has already been applied
  4. An invalid or corrupted stash

Answer: B. The most recently created stash

Explanation: Stash indices are ordered with {0} always representing the most recently created stash, with higher numbers representing progressively older ones.

3. What does git stash drop stash@{1} do?

  1. Restores stash@{1}'s changes and removes it from the list
  2. Permanently removes stash@{1} from the list without ever restoring its changes
  3. Restores stash@{1}'s changes but keeps it in the list
  4. Deletes all stashes at once

Answer: B. Permanently removes stash@{1} from the list without ever restoring its changes

Explanation: git stash drop removes a specific stash from the list entirely, without applying its saved changes to the working directory at all.

git stash pop / apply / list / drop: Common Mistakes Beginners Make

  • Using git stash pop by default and being confused later when an important stash is no longer in the list, not realizing pop removes it upon successful restoration.
  • Forgetting that stash indices shift after a pop or drop — what was stash@{1} may become stash@{0} once the previous top stash is removed.
  • Confusing git stash drop with discarding uncommitted working directory changes — drop only affects an already-saved stash, not your current working directory content.
  • Running git stash clear casually without first reviewing git stash list, accidentally losing multiple stashes that may still have been needed.

git stash pop / apply / list / drop: Exam-Ready Quick Notes

  • git stash list: shows all stashes, most recent as stash@{0}.
  • git stash pop: restores AND removes the (most recent, or specified) stash.
  • git stash apply: restores but KEEPS the stash in the list.
  • git stash drop <stash>: removes a specific stash without restoring it. git stash clear: removes ALL stashes at once.

git stash pop / apply / list / drop: Key Takeaways

  • git stash list is essential for keeping track of multiple accumulated stashes and identifying each by its index.
  • Choosing between pop and apply depends on whether you want the stash automatically cleaned up after restoration or intentionally kept around.
  • drop and clear provide precise (single-stash) and broad (all-stashes) cleanup options, respectively, for stashes you no longer need.

Frequently Asked Questions About git stash pop / apply / list / drop

Q1. What is the difference between git stash pop and git stash apply?

Both bring your stashed changes back into your working directory. pop additionally removes that stash from the saved list afterward, while apply keeps it in the list, letting you restore the same changes again later if you need to.

Q2. How do I see all the stashes I've currently saved?

Run git stash list, which shows every saved stash, most recent first, each labeled with an index like stash@{0}, stash@{1}, and so on.

Q3. How do I restore a stash that isn't the most recent one?

Specify its index explicitly, for example git stash pop stash@{1} or git stash apply stash@{1}, rather than relying on the default behavior, which always targets the most recent stash.

Q4. How do I delete a stash I no longer need without restoring it?

Use git stash drop <stash-index>, for example git stash drop stash@{1}, which permanently removes that specific stash from the list without ever applying its saved changes.

Q5. How can I delete all my stashes at once?

Run git stash clear. This is a more drastic, permanent operation that removes every currently saved stash at once, so it's a good idea to review git stash list first to make sure nothing important is still saved there.

Summary

Stashes accumulate in a stack, viewable with `git stash list`, where each is identified by an index like `stash@{0}` (most recent) or `stash@{1}` (next most recent), and so on. `git stash pop` restores a stash's changes into your working directory and removes it from the list afterward, while `git stash apply` restores the same changes but deliberately leaves the stash in place, useful if you might need to apply it again elsewhere. Both default to the most recent stash but can target any specific one by index. For cleanup, `git stash drop <stash>` permanently removes one specific stash without ever restoring it, while `git stash clear` removes every currently saved stash at once — a more drastic operation best used only once you're confident nothing saved is still needed.

Frequently Asked Questions

Both bring your stashed changes back into your working directory. pop additionally removes that stash from the saved list afterward, while apply keeps it in the list, letting you restore the same changes again later if you need to.

Run git stash list, which shows every saved stash, most recent first, each labeled with an index like stash@{0}, stash@{1}, and so on.

Specify its index explicitly, for example git stash pop stash@{1} or git stash apply stash@{1}, rather than relying on the default behavior, which always targets the most recent stash.

Use git stash drop <stash-index>, for example git stash drop stash@{1}, which permanently removes that specific stash from the list without ever applying its saved changes.

Run git stash clear. This is a more drastic, permanent operation that removes every currently saved stash at once, so it's a good idea to review git stash list first to make sure nothing important is still saved there.