Stop 02 · Git & GitHubTopics · 8/11

Stash

Part of the Full Stack Developer Roadmap

In short

You're halfway through a feature and an urgent bug lands. Stash lets you park your messy work, fix the bug, and come back to exactly where you were.

`git stash` temporarily shelves uncommitted changes so you can switch branches cleanly, then reapply them later with `git stash pop`.

The mascot slides a half-painted poster into a desk drawer and glances at the door.

Think of it like this

Shoving the craft project in a drawer

You're painting a poster when guests ring the bell. You slide the half-done poster into a drawer, open the door, and later pull it out exactly as it was. git stash is that drawer for unfinished changes.

Watch it happen

The stash is a stack

push(stash@{0}: WIP orders)
stash@{0}: WIP orders

Top of the stack is coloured

1/4git stash saves your half-done orders work. Your folder is clean again.

The big ideas

What you need to know

Clean folder, saved work

Stash saves changes in tracked files and resets them, so you can switch branches without committing junk.

Name your stashes

git stash push -m "half of order validation" makes git stash list readable a week later.

New files need -u

By default untracked files stay behind. git stash -u includes them.

Not long-term storage

Stashes are easy to forget. If work matters for more than a day, commit it on a branch.

See it in code

Walk through the code

bash
1git stash push -u -m "WIP: order validation"2git switch main3git switch -c fix/login-5004# ...fix the bug, commit, push...5 6git switch feature/orders7git stash list8# stash@{0}: On feature/orders: WIP: order validation9git stash pop                  # apply and remove10# git stash apply stash@{1}    # apply but keep it

1/4Park everything, including new files, with a helpful name.

pop applies and deletes. apply keeps the stash around, which is safer if you might need it again.

Save yourself the pain

Common mistakes

Oops

Stashing without -u and losing track of a new file you created.

Do this instead

Use git stash -u when you have new files, or check git status after stashing.

Oops

Piling up ten nameless stashes over a month.

Do this instead

Name each stash and clear old ones with git stash drop. For longer work, commit to a WIP branch.

Your mission

Handle an interruption

~10 min

Quick check

You run git stash (no flags) with an edited app.js and a brand-new notes.txt. What gets stashed?

Go deeper

  1. 1Make some uncommitted changes, stash them, switch branches, then pop them back.
  2. 2Learn `git stash list` and `git stash apply <n>` for managing multiple stashes.
  3. 3Practice `git stash push -m 'message'` to label stashes for clarity.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge