What Is Git Stash? A Practical Guide to Saving Work Without Committing
Git stash is a temporary holding area for uncommitted changes. If you need to switch branches, pause a half-finished task, or handle an urgent bug without creating a messy commit, git stash push –include-untracked gives you a clean way to park your work and come back to it later.
That is the core problem stash solves: you are not ready to commit, but you cannot keep editing the same branch forever. Developers use it when priorities change mid-stream, when a production issue takes over the day, or when they need to compare code without carrying unfinished changes along for the ride.
This guide explains what Git stash actually stores, how git stash push -u differs from the default behavior, when to use git stash push -m to label work clearly, and how to restore changes safely with git stash apply or git stash pop. You will also see real-world workflows, common mistakes, and practical troubleshooting steps.
Git stash is not version control history. It is a temporary workspace reset tool. Use it to save your progress quickly, not to archive work for days or weeks.
Understanding Git Stash and How It Fits Into Git
To understand what is git stash, you need the basic Git model. Git tracks code in three main places: the working directory, the staging area, and the commit history. Your working directory contains files you are actively editing. The staging area holds selected changes ready to commit. Commits are permanent snapshots in the repository history.
Uncommitted changes are edits that live in your working directory or staging area but have not yet been saved as a commit. That matters because Git expects a clean enough state for many operations. You can often switch branches with local modifications, but if the changes conflict with files on the target branch, Git will stop you to avoid overwriting work.
Git stash acts like a temporary shelf for those uncommitted changes. It saves the current state, clears the working tree, and lets you continue from a clean branch. Internally, stash entries are managed like a stack: the most recent stash is usually the first one you see in git stash list.
- Working directory: where you edit files
- Staging area: where you prepare changes for commit
- Commit history: permanent project record
- Stash stack: temporary saved work, ordered newest first
Note
Git stash is best thought of as a short-term pause button. It protects your current work while keeping the repository clean enough for branch changes, pulls, and urgent fixes.
For the official Git documentation on stash behavior and command options, the best reference is the Git SCM manual at Git SCM.
Why Developers Use Git Stash
Developers use stash because work rarely happens in a straight line. A feature branch may be halfway done when a critical bug arrives. A code review may need a fast pull from the main branch. A test may expose a problem that requires jumping to another branch before you are ready to commit anything.
Context switching is the most common reason. Instead of forcing a commit that says “wip” or “temporary fix,” you stash the current edits and move on. That keeps your Git history cleaner and reduces the chance that unfinished code gets mixed into an unrelated commit later.
It also helps with safe experimentation. If you want to try a risky refactor, update dependencies, or compare branch behavior, stash lets you preserve your starting point. If the experiment goes nowhere, you can recover the exact state you had before the test.
Common scenarios where stash makes sense
- Production bug interrupts feature work: save your current branch state, switch to the hotfix, and return later
- Code review starts mid-task: stash incomplete edits, pull the latest branch, and verify reviewer comments
- Branch change is required: save local changes before checking out a branch with different file conflicts
- Need a clean test run: stash local modifications so you can reproduce a problem in a known state
For teams that follow disciplined version control practices, stash supports clean workflows without forcing premature commits. That aligns well with branch-based development models used in many organizations and documented in broad version control guidance such as Microsoft Learn and general Git workflows referenced by the Git project itself.
A good stash saves time later. A bad stash is a hidden pile of forgotten work. The difference is usually naming, discipline, and how quickly you come back to it.
What Git Stash Actually Saves
By default, Git stash saves tracked file changes. That includes modified files that Git already knows about, and staged changes that you have added with git add. In other words, stash captures the current snapshot of your work in progress, then resets your working directory to a cleaner state.
What surprises many developers is that untracked files are not included by default. If you create a brand-new file and do not stage it, standard stash behavior will leave it behind. That is why git stash push -u or git stash push –include-untracked matters: it tells Git to include those new files too.
This distinction prevents a common mistake. You think you have “saved everything,” but later discover the new config file, test fixture, or script was never stored in the stash. That can cause confusion when the working tree looks clean but the real change set was only partially preserved.
What gets stored and what does not
- Included by default: modified tracked files and staged changes
- Excluded by default: untracked files
- Optional with flags: untracked files through
-uor--include-untracked - Temporary by design: stash is not the same as a commit
That is why understanding stash scope matters. If you work with generated files, test data, or new source files, confirm whether they are tracked before relying on the stash. The official command behavior is documented in Git SCM, which is the safest source for exact option behavior.
Warning
If a file is untracked and you do not use git stash push -u or git stash push --include-untracked, it will not be saved. That is one of the most common reasons developers think stash “lost” work.
Basic Git Stash Commands
The simplest command is git stash, but modern Git usage often favors the explicit form git stash push. Both are used to save local changes, but push is clearer when you are reading or scripting commands because it states the action directly.
If you want to make a stash easier to identify later, use git stash push -m. The message option lets you attach a label such as git stash push -m "pause feature login validation". That is much better than digging through several anonymous stash entries later.
When you need to see what is saved, use git stash list. Each entry appears in order, usually with the most recent stash at the top. To restore a stash without deleting it, use git stash apply stash@{0}. If you want to restore and remove it at the same time, use git stash pop.
Command comparison
| Command | What it does |
git stash push |
Saves tracked changes into the stash stack |
git stash push -u |
Saves tracked changes plus untracked files |
git stash push --include-untracked |
Same practical result as -u; clearer in scripts and documentation |
git stash push -m "message" |
Stores a human-readable message with the stash entry |
git stash apply stash@{0} |
Restores a stash but keeps it in the list |
git stash pop |
Restores a stash and removes it if successful |
For command details, examples, and option behavior, consult the official Git documentation at Git SCM. If you use Git through Microsoft-centric workflows, Microsoft’s documentation at Microsoft Learn is also useful for branch and repository basics.
Practical Workflow for Stashing and Restoring Work
The standard workflow is simple, but the details matter. Start with local edits, stash them, switch to the branch you need, then restore the stash when you return. That sounds basic, but this is where many developers choose the wrong stash entry or restore changes onto an incompatible branch.
A clean workflow usually looks like this: you are editing a feature branch, a production incident interrupts you, and you need to move fast. Instead of committing a half-finished change, you run git stash push -m "pause login feature before bug fix". If you also have new files, include them with git stash push --include-untracked or git stash push -u.
After that, switch branches and handle the urgent work. When you are ready to resume, check git stash list so you restore the right snapshot. Use git stash apply stash@{0} if you want to keep the backup around, or git stash pop if you are confident the restore is clean.
- Make your edits on the current branch
- Run
git stash push -m "clear message" - Use
git stash listto confirm the stash exists - Switch branches and complete the urgent task
- Return to the original branch
- Apply or pop the stash and test the result
Key Takeaway
Use apply when you want a safety copy. Use pop when you are confident the restore will succeed and you no longer need the stash entry.
After restoring, always inspect the files and run tests relevant to the changes. A stash can restore content, but it cannot restore the full context of your interrupted work, especially if the branch moved forward in the meantime. That is why many teams treat stash as a temporary pause, not a long-term workflow.
Managing Multiple Stashes Effectively
Active developers often accumulate multiple stashes in a short time. A morning interruption becomes a second stash after lunch. Another urgent branch switch adds a third. Before long, the stash list becomes a cluttered pile of unlabeled snapshots that nobody wants to sort through.
That is where the stash stack concept helps. Git stores stashes in order, and the newest item is typically the one you see as stash@{0}. Older entries move down the list. This makes sense if you think of stashes as a stack of temporary work items rather than a branch history.
Good message discipline is the difference between useful and unusable stash lists. A message such as git stash push -m "before API refactor" is much easier to recognize than a generic anonymous stash. If you know what the stash is for, you can safely leave it alone or remove it later.
Cleaning up old stashes
git stash drop stash@{0}removes one stash entrygit stash clearremoves all stashesgit stash listshows what you still have savedgit stash show -p stash@{0}helps inspect the contents before deleting
Use drop when one stash is no longer needed. Use clear only when you are sure nothing valuable remains. If the stash list has become a junk drawer, review it before cleaning up. Once a stash is deleted, recovery is not something you should assume will be easy.
The official Git documentation remains the primary reference for these commands at Git SCM. For teams standardizing Git usage, a consistent naming convention for stash messages is often more valuable than any single command.
Common Real-World Use Cases for Git Stash
One of the best ways to understand git stash push –include-untracked is to look at the situations where it saves real time. The command is not about Git theory. It is about avoiding friction when development work gets interrupted.
Interrupted workflow is the classic case. You are halfway through a UI change, then a production bug arrives. Stash the current work, handle the incident, and return when the pressure drops. Without stash, you risk either committing unfinished code or leaving your branch in a messy state.
Feature branching is another practical use. Maybe one branch is waiting on review while you need to start a different task. Instead of creating a throwaway commit or mixing unrelated work, stash the current state and switch cleanly. That keeps each branch easier to understand and review.
Experimentation is also a strong fit. If you want to test a risky change, compare two implementation approaches, or temporarily edit configuration files, stash lets you protect the original work before trying something new. If the experiment fails, you still have your starting point.
- QA or review fixes: stash before pulling the latest changes
- Hotfix work: stop feature development without losing context
- Multi-tasking: keep parallel changes from bleeding together
- Branch cleanup: return to a clean tree before rebasing or merging
Stash works best when it removes interruption, not when it becomes the workflow. If you are keeping the same changes in stash for days, you probably need a branch instead.
Git Stash Best Practices
Good stash habits save time and prevent mistakes. The first rule is simple: always use a message when the stash matters. git stash push -m "message" tells future you why the stash exists. Without that context, even a few entries can become hard to sort out.
The second rule is to keep stash temporary. If work is important enough that you are nervous about losing it, it probably deserves a commit on a feature branch. Stash is ideal for interruption management, not long-term storage. That is especially true when your branch history, review process, or release process depends on clean commits.
Practical habits that reduce mistakes
- Name every meaningful stash so you can identify it later
- Review the stash list regularly and remove old entries you no longer need
- Test after restore to catch partial context or merge issues early
- Use branches for larger work instead of stacking stashes indefinitely
If you are working in a team with strict code review or release practices, stash should complement your branching strategy, not replace it. That principle aligns with standard Git usage documented in official Git resources and broader version control guidance from vendor documentation such as Microsoft Learn.
Pro Tip
If a stash represents more than a few minutes of work, consider creating a branch instead. Branches are discoverable, reviewable, and safer for anything you need to keep around.
Git Stash Limitations and Common Pitfalls
Stash is useful, but it is not a backup system. It does not replace commits, remote copies, or a sound branching strategy. If your machine fails or your local repository is damaged, you should not assume stash will protect you in the way a committed branch or remote repository would.
One common pitfall is forgetting that untracked files are excluded unless you use git stash push -u or git stash push –include-untracked. Another is assuming that git stash pop will always succeed cleanly. If the branch has changed a lot since the stash was created, applying it may trigger conflicts.
Old stashes can also create false confidence. They sit quietly in the list until one day someone assumes the work is safe, only to find the context has drifted so far that the stash is difficult to use. That is why keeping stash entries short-lived is important.
What stash is not meant to do
- Not a backup: it is local and temporary
- Not a branch: it does not provide a working history for collaboration
- Not archival storage: it is not where long-term work should live
- Not conflict-free: restore operations can still fail
If you need an authoritative reference for stash limitations and command behavior, use Git SCM. For broader version control strategy, official platform documentation is often the best place to confirm how stash fits into the rest of your workflow.
Troubleshooting Stash-Related Issues
When a stash does not apply cleanly, the first step is to stop and inspect the state of both the stash and the branch. Do not keep retrying blindly. Conflicts usually mean the target branch has moved, the files changed too much, or you selected the wrong stash entry.
Start by checking git stash list. Confirm that you are restoring the right entry, especially if you have multiple stashes. Then inspect the stash contents with git stash show -p stash@{n} so you know exactly what is inside before applying it again.
If the restore fails, resolve the conflicts the same way you would during a merge: open the files, identify conflict markers, and decide which content should stay. Once resolved, stage the fixed files and continue testing. If the stash contains especially important work, create a backup commit or branch before making more changes.
- Check the correct
stash@{n}entry - Inspect the patch with
git stash show -p - Confirm branch state with
git status - Resolve conflicts carefully if they appear
- Validate the restored work with tests or a build
Warning
If the stashed work is important, create a backup branch or commit before applying it to a changing codebase. That is the safest way to avoid losing time to repeated conflict resolution.
People also search for phrases like abort apply stash, abort git stash, and abort git stash apply. In practice, the safe response is to halt the restore, inspect the conflict, and either reset the working state or reattempt the apply on a cleaner branch. If you need a clean exit from a bad restore, use standard Git recovery steps such as checking status, resolving or discarding local conflict markers, and then retrying only after you understand what failed.
For technical accuracy on Git command behavior, the official reference remains Git SCM. If your Git usage is tied to a platform-specific workflow, vendor documentation from the platform you use should also be part of your troubleshooting checklist.
Conclusion
Git stash is a fast, practical way to save unfinished work without committing it. It helps you switch tasks cleanly, protect progress during interruptions, and keep your repository in a usable state while you handle something else.
The key habits are straightforward: use git stash push -m to name your work, use git stash push -u or git stash push –include-untracked when untracked files matter, restore carefully with git stash apply or git stash pop, and clean up old entries before the stash list becomes cluttered.
If you treat stash as a temporary tool inside a broader Git strategy, it works very well. Use branches for real work, commits for durable history, and stash for interruptions. That combination keeps your workflow clean and your progress safe.
For more practical Git guidance, keep reading official documentation and apply the command patterns you use most often in your own projects. ITU Online IT Training recommends making stash part of a disciplined Git workflow, not a substitute for one.
Git is a registered trademark of the Software Freedom Conservancy, Inc.