Git Stash: How to Save Changes Without Committing
Need to switch branches before your work is ready to commit? Git stash temporarily stores changes from your working tree so you can return to them later. This guide explains how to stash, find, and restore work safely.
Practice Git workflows →What does git stash do?
git stash saves tracked changes that have not been committed and returns those files to the state of the latest commit. Your changes are stored in a local stash entry, separate from your commit history. It is useful when you need a clean working tree to change branches, pull updates, or investigate another task.
A stash is not a permanent backup or a commit. If the work matters, commit it when practical, and avoid using git stash clear unless you are certain you no longer need any saved entries.
How to stash changes in Git
- Check what is changed with
git status. - Save tracked changes with
git stash push -m "work in progress". The message makes the entry easier to recognize later. - Confirm the working tree is clean with
git status, then switch branches or do the other work you need.
By default, untracked files are not included. To stash tracked and untracked files together, use git stash push -u -m "work in progress". The -u option does not include ignored files.
How to find and inspect a stash
List saved entries with git stash list. Each one gets a reference such as stash@{0}; the entry at index zero is the newest. To inspect its summary, run git stash show stash@{0}. Add -p to review the saved diff before restoring it.
Stashes belong to the local repository. They are not pushed to a remote, so another clone or teammate will not automatically receive them.
git stash pop vs. git stash apply
Use git stash pop to apply the newest stash and remove that entry if it applies successfully. It is convenient when you are done with the saved copy.
Use git stash apply to restore changes while keeping the stash entry. This is safer when you want to test the result first or may need to apply it again. To apply a specific entry, pass its reference, for example git stash apply stash@{1}.
Either command can produce merge conflicts if the current files changed since you created the stash. Resolve the conflicts like other merge conflicts, review the result, and then decide whether to keep or drop the stash entry.
Remove a stash when you no longer need it
After confirming your changes are restored and safe, remove one entry with git stash drop stash@{0}. The reference number can change when entries are added or removed, so check git stash list immediately before dropping one. Avoid git stash clear unless you intend to delete every stash entry in the repository.
Git stash FAQ
Does git stash save untracked files?
Not by default. Use git stash push -u to include untracked files, or -a if you also intend to include ignored files.
Does git stash delete my changes?
It removes the stashed changes from the working tree after saving them in a local stash entry. Check git stash list to confirm the entry exists before continuing.