Devops

Git Stash Explained: Save Work Instantly Without Committing

April 6, 2026
Published
#Developer Tools#DevOps#Git#GitHub#Version Control

You’re halfway through a feature when a teammate pings you: “Hey, can you quickly fix this bug on another branch?”

You’ve got uncommitted changes. They’re messy. They’re incomplete. And committing them just to switch context feels wrong.

This is exactly where Git stash shines.

What Git Stash Actually Does

At its core, Git stash temporarily shelves your working directory changes so you can work on something else, then come back later and restore them.

Think of it like putting your work into a drawer instead of committing it to history.

Quick mental model

  • Working directory = your current edits
  • Stash = temporary storage
  • Commit = permanent history

Stashing is not a replacement for commits. It’s a short-term escape hatch.

The Basic Workflow

Let’s start with the simplest use case.

1. Stash your changes

TEXT
1git stash

This command:

  • Saves your modified tracked files
  • Reverts your working directory to a clean state

2. Switch branches

TEXT
1git checkout main

3. Come back and restore

TEXT
1git stash pop

Now your changes are back, exactly where you left them.

Here’s Where Things Get Interesting

Most developers only use git stash and git stash pop. But stash has a lot more depth—and ignoring it leads to messy workflows.

Named stashes (you’ll thank yourself later)

Instead of creating anonymous stashes, give them context:

TEXT
1git stash push -m "WIP: checkout form validation"

This becomes incredibly useful when you have multiple stashes.

List your stashes

TEXT
1git stash list

Example output:

JSON
1stash@{0}: On feature/cart: WIP: fix pricing bug
2stash@{1}: On main: WIP: navbar redesign

Apply a specific stash

TEXT
1git stash apply stash@{1}

Unlike pop, this does not remove it from the stash list.

Pop vs Apply (Common Confusion)

This trips up a lot of people.

CommandWhat it does
git stash popApplies changes and removes stash
git stash applyApplies changes but keeps stash

Use pop when you’re done with the stash. Use apply when you might need it again.

Stashing Untracked Files

By default, Git stash ignores untracked files.

If you want to include them:

TEXT
1git stash -u

Or even include ignored files:

TEXT
1git stash -a

This is useful when you're working with generated files or temporary assets.

A Real-World Scenario

Let’s say you’re working on a React component:

  • You’ve modified multiple files
  • The code doesn’t compile yet
  • A production bug needs urgent fixing

Instead of committing broken code:

TEXT
1git stash push -m "WIP: product card redesign"
2
3git checkout hotfix/login-issue

Fix the bug, push it, then come back:

TEXT
1git checkout feature/product-card
2
3git stash pop

You resume exactly where you left off—no messy commit history.

Partial Stashing (Underrated Feature)

Sometimes you don’t want to stash everything.

You can stash interactively:

TEXT
1git stash -p

This lets you choose which changes to stash, chunk by chunk.

Useful when:

  • You’re working on multiple unrelated changes
  • You only want to pause part of your work

Cleaning Up Your Stashes

Stashes can pile up quickly.

Drop a specific stash

TEXT
1git stash drop stash@{0}

Clear everything

TEXT
1git stash clear

Be careful—this is irreversible.

Common Mistakes Developers Make

1. Using stash as long-term storage
Stash is temporary. If something matters, commit it properly.

2. Forgetting about stashes
Old stashes can become irrelevant or incompatible with newer code.

3. Not naming stashes
“stash@{3}” tells you nothing. Always add context.

4. Assuming stash is branch-specific
Stashes are repository-wide. You can apply them on any branch.

When You Should (and Shouldn’t) Use Git Stash

Good use cases

  • Quick context switching
  • Interrupt-driven work
  • Temporary experimentation

Not ideal for

  • Long-running work
  • Collaboration
  • Anything you might forget

A Small Trick That Saves Time

You can stash and switch branches in one go:

TEXT
1git stash && git checkout main

Or even:

TEXT
1git stash push -m "quick save" && git switch main

Not groundbreaking, but handy in fast-paced workflows.

Wrapping It Up

Git stash is not just a convenience—it’s a workflow accelerator.

It keeps your commit history clean, lets you multitask safely, and removes the pressure to commit unfinished work.

Once you start naming stashes, using partial stash, and understanding apply vs pop, it becomes a much more powerful tool than most developers realize.

If you’ve ever made a “WIP commit” just to switch tasks, Git stash is the cleaner alternative.

Comments

Leave a comment on this article with your name, email, and message.

Loading comments...

Similar Articles

More posts from the same category you may want to read next.

Share: