Blog
4 min read

Git Stash Explained: Save Unfinished Work Without Committing

git stash puts your uncommitted changes aside so you can switch branches or pull, then brings them back later. How stash, pop, apply and list work, stashing untracked files, naming stashes, recovering a dropped stash, and when a quick commit is better.

You're halfway through a change when you need to switch to another branch — to fix an urgent bug, or pull the latest code. Git refuses: "Your local changes would be overwritten." You're not ready to commit. git stash is the answer: it puts your unfinished changes on a shelf, gives you a clean working folder, and lets you bring them back later.

(New to git? Start with Git and GitHub for beginners and git branches explained.)

The basic loop

git stash          # shelve your changes; working folder is now clean
git switch main    # do whatever you needed to
# ...fix the bug, commit, push...
git switch my-feature
git stash pop      # bring the changes back

That's 90% of what you'll use it for.

The commands

Command What it does
git stash Save tracked changes and clean the working folder
git stash push -m "message" The same, with a name so you can find it later
git stash list Show all stashes
git stash pop Re-apply the most recent stash and remove it from the list
git stash apply Re-apply it but keep it in the list
git stash drop Delete the most recent stash
git stash show -p See what's in the most recent stash

Stashes form a stack: the newest is stash@{0}, then stash@{1}, and so on.

$ git stash list
stash@{0}: On my-feature: half-done search filters
stash@{1}: WIP on main: 3f9a2c1 Fix header

To work with an older one:

git stash apply stash@{1}
git stash drop stash@{1}

New files aren't stashed by default

A plain git stash only saves changes to files git already tracks. New, untracked files stay behind in your working folder. To include them:

git stash -u        # or --include-untracked

Ignored files (like node_modules or .env) are left alone either way, which is usually what you want. (What is .gitignore?)

Stashing only some files

git stash push src/search.ts src/filters.ts -m "search work"

or interactively choose pieces with git stash push -p (it asks about each change).

When pop has a conflict

If the code changed since you stashed, git stash pop can hit a merge conflict. Git applies what it can and marks the conflicts in the files, exactly like a merge. Resolve them (merge conflicts explained), then git add the files.

When a pop conflicts, the stash is kept in the list (git doesn't drop it until it applies cleanly), so nothing is lost. Once you've resolved everything, remove it with git stash drop.

Turning a stash into a branch

If you stashed something and later realise it deserves its own branch:

git stash branch new-idea

creates a branch from the commit you stashed on, applies the stash there, and drops it.

"I dropped a stash I needed"

Dropped stashes aren't immediately destroyed. You can usually find them:

git fsck --no-reflog | grep commit

then inspect candidates with git show <hash> and recover with git stash apply <hash>. It's fiddly — see how to undo almost anything in git — but it works if you act before git cleans up.

Stash vs a quick "WIP" commit

Stashes are easy to forget. Weeks later, git stash list has twelve entries named "WIP on main" and you don't know what any of them are. For anything you'll come back to after more than a few minutes, many people prefer committing on a branch instead:

git switch -c wip/search-filters
git commit -am "WIP: search filters"

A commit on a branch is visible, named, pushed to GitHub if you like, and can be tidied up later. Use stash for short interruptions.

Stash and AI coding tools

AI agents sometimes run git stash to get a clean state before a task — and then forget to pop it, so your changes seem to vanish. If work disappears after an agent session, check git stash list first. Better: commit your own work before handing over to an agent, so its changes and yours stay separate. (Claude Code checkpoints are another safety net.)

The summary

  • git stash shelves uncommitted changes; git stash pop brings them back.
  • Use -u to include new files and -m to name stashes.
  • Conflicts on pop are resolved like merge conflicts; the stash is kept until you drop it.
  • For longer pauses, a WIP commit on a branch is easier to keep track of.

EasySpawn keeps your project, git history and uncommitted work on a persistent server, so it's exactly where you left it — from your laptop, your phone, or the next session. See how it works or join the waitlist.

Related: Git Rebase vs Merge · How to Read a Diff · Write Good Commit Messages · Running Claude Code Agents in Parallel With Git Worktrees

Keep reading