Stashing Changes

What stashing is for

You're in the middle of editing, then something urgent comes up — you need to switch branches, or pull the latest code, but your changes aren't ready to commit. git stash takes your uncommitted changes, tucks them away, and gives you a clean working tree. Later you pop them back exactly where you left off.

Mental model: stash is a clipboard for changes. Cut now, paste back soon. It's meant to be temporary — not a place to store work for days.

Stash your changes

Running git stash shelves all your tracked, modified files. Add a message so you remember what it was — handy if you end up with more than one stash.

Shelve your work

Terminal
$ git stash                       # quick shelve
$ git stash push -m "half-done navbar"  # with a label
In VS Code
  1. Source Control panel → '…' menu → Stash
  2. Type an optional message when prompted

By default stash ignores brand-new (untracked) files — see the -u tip below if you need those too.

See and restore your stashes

git stash list shows what you've shelved. Bring the newest one back with git stash pop — it re-applies the changes and removes it from the list.

List and bring back

Terminal
$ git stash list
$ git stash pop          # apply the latest stash and remove it
$ git stash apply        # apply it but KEEP it in the list
In VS Code
  1. Source Control → '…' → StashPop Stash… (or Apply Stash)
  2. Pick which stash to restore from the list

pop = apply + delete. apply = apply but keep it, in case you want it again on another branch.

Manage multiple stashes

Stashes form a stack — the newest is stash@0. You can pop a specific one, throw one away, or clear them all.

Pick, drop or clear

Terminal
$ git stash pop stash@{1}    # restore a specific stash
$ git stash drop stash@{0}   # delete one without applying
$ git stash clear            # delete ALL stashes
In VS Code
  1. The Stash menu lists each stash with its message so you can choose
  2. Drop Stash… removes one you no longer need

Include untracked files: brand-new files aren't stashed by default. Add -u to include them: git stash -u (or git stash push -u -m "msg").

When pop hits a conflict

If the code changed while your work was shelved, git stash pop can raise a conflict — the same situation as a merge conflict, and the same fix. One quirk to know: a conflicted pop does not delete the stash, so once you've resolved it you drop the stash yourself.

Resolve a conflicted pop

Terminal
$ git stash pop
$ # CONFLICT → fix the file, then: git add .
$ git stash drop   # a conflicted pop keeps the stash; drop it once resolved
In VS Code
  1. Conflicted files appear under Merge Changes — resolve them like any merge (see Fix Merge Conflicts)
  2. Then '…' → StashDrop Stash… to remove the now-applied stash

Stash or a quick commit?

Stash is great for a short detour — pull, peek at another branch, then come straight back. If the work will sit for a while, a small "WIP" commit on a branch is safer and clearer: it's backed up, shows in your history, and won't get lost in a forgotten stash. You can always tidy it later with git commit --amend or git reset (see the Undo Commits chapter).

Up next: the GitHub side — starting with the one-time sign-in that makes push and pull work, in VS Code and the terminal.

FAQ

Frequently Asked Questions

What does git stash do?
It shelves your uncommitted changes and gives you a clean working tree, so you can switch branches or pull. git stash pop brings the changes back later.
What is the difference between git stash pop and apply?
pop re-applies the most recent stash and removes it from the list. apply re-applies it but keeps it, so you can reuse the same stash elsewhere.
Does git stash include new (untracked) files?
Not by default — untracked files are skipped. Use git stash -u to include them.
Where do stashed changes go?
Into a stack you can view any time with git stash list. They stay there until you pop, drop, or clear them.
What if git stash pop causes a conflict?
Fix the marked file like any merge conflict (see Fix Merge Conflicts), then git add it. One quirk: a conflicted pop keeps the stash in the list — run git stash drop once you've resolved it.