Skip to main content
March 23, 2026/2 min read

Stash: git stash

Master Git stash commands for better workflow management

Prerequisites

All commands require you to navigate to your Git repository folder first. Ensure you have Git installed and a repository initialized before proceeding.

For All the Commands Below

The commands below assume you've navigated to the working directory of your Git repository. Ensure you're in the correct project folder before executing any stash operations to avoid unintended consequences.

Create a Stash

Git stash is your safety net when you need to quickly switch contexts without committing incomplete work. Whether you're responding to an urgent bug fix or switching branches mid-feature, stashing preserves your uncommitted changes in a temporary storage area. To stash your current work, use one of these commands:

  • git stash
  • git stash save "A meaningful name/message"
  • NOTE: You can maintain multiple stashes simultaneously, creating a stack of saved states. While naming isn't mandatory, descriptive messages like "WIP: user authentication module" or "before refactoring payment logic" will save you time when working with multiple stashes.

Git Stash Command Options

FeatureBasic StashNamed Stash
Commandgit stashgit stash save "message"
OrganizationHarder to identifyEasy to identify
Best forQuick temporary savesMultiple ongoing changes
Recommended: Use named stashes when managing multiple work streams
Multiple Stashes Supported

Git allows you to create multiple stashes. While naming is optional, meaningful names help identify stashes later, especially when working on different features simultaneously.

List Stashes

As your stash collection grows, you'll need visibility into what you've stored. This becomes particularly valuable during long development cycles or when collaborating on complex features.

  • git stash list

Understanding Stash List Output

Stash Index

Each stash gets a unique identifier like stash@{0}, stash@{1}. Lower numbers indicate more recent stashes.

Stash Message

Shows your custom message or default branch information. Helps identify the purpose of each stash.

Restore/Apply a Stash

When you're ready to resume your previous work, Git provides flexible options for applying stashed changes. The key distinction lies in whether you want to preserve the stash for future use or remove it once applied:

  • git stash pop
    • To apply a specific stash and remove it from your stash list, use the following command. Replace stash@{0} with your target stash identifier from the stash list:
  • git stash pop stash@{0}
    • To apply a specific stash while keeping it in your stash list for potential reuse, execute this command. Again, replace stash@{0} with your desired stash reference:
  • git stash apply stash@{0}

Pop vs Apply Commands

Featuregit stash popgit stash apply
Stash removalRemoves from listKeeps in list
Use caseOne-time applicationMultiple applications
Risk levelHigher - stash deletedLower - stash preserved
Recommended: Use apply for testing changes, pop for final implementation

Applying Specific Stashes

1

List Available Stashes

Run git stash list to see all available stashes with their identifiers

2

Identify Target Stash

Note the stash identifier (e.g., stash@{0}, stash@{1}) for the changes you want

3

Apply the Stash

Use git stash pop stash@{0} or git stash apply stash@{0} with your specific identifier

Removing Stashes

Stash maintenance is crucial for keeping your repository clean and avoiding confusion. Over time, accumulated stashes can become noise, making it harder to locate relevant saved work.

  • git stash clear

To delete a specific stash while preserving others, use the targeted removal command. Replace stash@{0} with the exact stash identifier you want to eliminate:

  • git stash drop stash@{0}

Git Stash Clear vs Drop

Pros
Clear removes all stashes at once for complete cleanup
Drop allows selective removal of specific stashes
Both commands free up repository storage space
Helps maintain organized stash history
Cons
Clear is irreversible and removes all stashed work
Drop requires identifying specific stash numbers
Accidentally removing needed stashes loses work
No built-in recovery mechanism for deleted stashes
Permanent Deletion Warning

Both git stash clear and git stash drop permanently delete stashed changes. Make sure you no longer need the stashed code before removing it.

Go Beyond Git

Mastering Git is just the beginning of your development journey. Whether you're looking to advance your current role or pivot into tech, our comprehensive curriculum covers the full spectrum of modern development skills:

Available NYC Coding Programs

Web Development School

Comprehensive full-stack development training. Learn front-end and back-end technologies in hands-on, expert-led classes.

Python Bootcamp

Intensive Python programming course covering fundamentals to advanced topics. Small class sizes ensure personalized attention.

Data Science School

Master data analysis, machine learning, and statistical modeling. Practical projects with real-world datasets and expert instruction.

Web Design School

Learn modern design principles, user experience, and visual design. Hands-on training with industry-standard tools and techniques.

Key Takeaways

1Git stash temporarily saves uncommitted changes without creating a commit, allowing you to switch branches or pull updates cleanly
2Multiple stashes can exist simultaneously, and naming them with meaningful messages improves organization and identification
3The git stash list command displays all saved stashes with their identifiers and descriptions for easy reference
4Git stash pop removes the stash after applying it, while git stash apply keeps the stash available for future use
5Specific stashes can be targeted using their identifier (stash@{0}, stash@{1}) rather than just applying the most recent one
6Git stash clear permanently deletes all stashes, while git stash drop removes only a specific targeted stash
7Stashing is essential for maintaining clean git history and avoiding unwanted commits of incomplete work
8All git stash commands must be executed from within the Git repository directory to function properly

RELATED ARTICLES