Git stash uncached how to put away all unstaged changes?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When people ask how to stash only unstaged changes, they usually want to preserve the current staged snapshot while temporarily hiding everything that is still only in the working tree. Git can do that, but it helps to think clearly about the difference between the index and the working tree before reaching for git stash.
Core Sections
Understand what is staged and what is unstaged
Git tracks changes in at least two places that matter here:
- the index, also called the staging area
- the working tree, which is what is currently on disk
If a file has been added with git add, its current content is in the index. If you edit it again without re-adding it, those later edits are unstaged changes in the working tree.
That distinction matters because a normal git stash stores both staged and unstaged modifications together. If your goal is to keep the staged work ready for commit and put away only the unstaged edits, you need a more specific command.
Use git stash --keep-index
The standard answer is git stash --keep-index. This tells Git to stash the working-tree changes while leaving the index as it is.
After this command:
- staged changes remain staged
- unstaged changes are moved into the stash
- the working tree is cleaned back to match the index
This is useful when you have already prepared a logical commit but still have unrelated in-progress edits that you want out of the way temporarily.
A simple example workflow
Suppose you have a tracked file and you stage one set of edits, then continue editing the same file.
At this point, the first version is staged and the second edit is unstaged. Running:
removes the unstaged edit from the working tree while preserving the staged snapshot. You can now run tests, make a focused commit, or switch tasks without losing the extra work.
Add untracked files if needed
By default, git stash --keep-index does not include untracked files. If your unstaged work also includes newly created files that are not yet tracked, add -u.
That combination is often what people really need when they say "stash all unstaged changes," because newly created files are part of the working tree state even though they are not in the index.
Inspect and restore the stash deliberately
Once the changes are stashed, you can inspect them with:
And restore them later with either:
or:
apply restores the stash but keeps it in the stash list. pop restores it and then removes it if the apply succeeds. When the work matters, apply is the safer first choice because it avoids losing the stash entry during conflict resolution.
When to prefer another workflow
If you use this pattern often, it may be a signal that your working style needs smaller branches or more frequent commits. git stash --keep-index is useful, but it should not become the primary way you partition work indefinitely.
In many cases, these are better long-term strategies:
- commit small, coherent changes sooner
- use a temporary branch for experiments
- use patch mode such as
git add -pto stage more precisely
stash is strongest as a short-lived context switch tool, not a long-term storage mechanism.
Common Pitfalls
- Running plain
git stashinstead ofgit stash --keep-indexstashes the staged changes too, which is not the intended result. - Forgetting
-uleaves untracked files behind and makes it seem like the stash only half-worked. - Using
git stash popimmediately can be risky if you expect conflicts and would rather keep the stash entry until the apply is confirmed. - Treating stash as long-term storage makes it easier to lose track of work or forget what each stash contains.
- Not checking
git statusbefore and after the stash often leads to confusion about what remained staged versus what was stored away.
Summary
- To stash only unstaged changes while keeping staged changes intact, use
git stash --keep-index. - Add
-uif untracked files should be included too. - '
git stash listandgit stash show -phelp verify what was saved.' - '
applyis safer thanpopwhen conflicts are possible.' - If this pattern becomes routine, consider whether smaller commits or branch isolation would be a better workflow.

