Command guide · Stash
git stash: save work without committing
git stash saves your uncommitted changes and gives you a clean working directory, without making a commit. Later, git stash pop brings the changes back. It's the go-to command when you need to switch branches in the middle of something.
Quick answer
Park your work: git stash. Bring it back: git stash pop.
When to use git stash
- You're halfway through a feature and need to fix an urgent bug on another branch.
git pullrefuses to run because your local edits would be overwritten.- You started work on the wrong branch and want to move the changes.
Basic stash workflow
git stash # save changes, clean the working tree
git switch hotfix # do other work
git switch feature # come back
git stash pop # restore the changes
Every stash command you'll need
| Command | What it does |
|---|---|
git stash | Stash tracked changes (staged and unstaged). |
git stash -u | Also stash untracked (new) files. |
git stash push -m "note" | Stash with a label so you can find it later. |
git stash list | List all stashes: stash@{0} is the newest. |
git stash show -p stash@{1} | Show the full diff of a stash. |
git stash pop | Apply the newest stash and delete it. |
git stash apply stash@{1} | Apply a specific stash and keep it. |
git stash branch new-branch | Create a branch from a stash. Useful when popping causes conflicts. |
git stash drop stash@{1} | Delete one stash. |
git stash clear | Delete every stash. Can't easily be undone. |
Move changes to another branch
git stash
git switch correct-branch
git stash pop
If git stash pop causes a conflict
Git applies what it can and marks the conflicting files, just like a merge. Fix the conflicts, git add the files, and the stash stays in the list (a conflicted pop doesn't drop it). Once you're happy, remove it with git stash drop.
FAQ
What is the difference between git stash pop and git stash apply?
Both bring stashed changes back. pop then deletes the stash from the list; apply keeps it, so you can apply it again elsewhere.
Does git stash save untracked files?
Not by default. Use git stash -u to include untracked files, or git stash -a to also include ignored files.
Where are stashes stored?
Locally, in your repository. Stashes are never pushed to a remote, so they don't leave your machine.