`git stash push -u` Is the Version You Should Learn If Untracked Files Keep Ruining Context Switches
A practical git stash guide focused on stash push, include-untracked behavior, and why stashing gets easier once you stop treating it like a mysterious panic button.
Why stash feels unreliable to people: many developers learn a vague version of stash early, then hit a case involving untracked files or path-specific work and conclude the command is random. Usually the problem is that the workflow stayed too vague.
Why stash push matters
Modern Git documentation explicitly emphasizes git stash push. Older habits often still use shorter or older forms, but push is the form that makes the intent clearest and supports pathspec behavior properly.
A simple example:
git stash push -m "wip before branch switch"That is already better than making an unnamed stash and hoping you remember why it exists later.
Why -u changes everything
By default, stash does not include untracked files. That is exactly why people switch branches and then get surprised that a newly created local file is still sitting there.
If you want untracked files included:
git stash push -u -m "save tracked and untracked work"That one flag solves a lot of “I thought I stashed everything” confusion.
Why this matters for context switching
Branch switching is often not blocked by tracked edits alone. It is blocked by local scratch files, generated artifacts, or not-yet-added work. If you do not understand whether those are included, your stash workflow stays half-trustworthy.
That is why -u is such an important everyday option for many developers.
The commands worth pairing with it
Creating a stash is only half the workflow. You should also be comfortable with:
git stash list
git stash show -p stash@{0}
git stash popThis is how stash stops being a black box. You can see what you saved, inspect the patch, and choose whether to apply and remove it in one step.
When stash is the wrong answer
Do not use stash as long-term storage for half-finished ideas you want to remember next month. That is how teams end up with forgotten, unnamed state nobody trusts. Stash is strongest as a temporary context-switch tool. If the work matters, put it on a branch. If the switch is brief, stash is perfect.
That distinction makes the command feel more reliable because you stop asking it to do jobs it was never meant to handle.
A practical switching pattern
If you are about to review another branch and your current directory contains edits plus a new scratch file, the safe routine is:
git stash push -u -m "wip before review"- switch context
- come back later
- inspect or pop the stash intentionally
That is much better than guessing whether Git quietly remembered every piece of local state you cared about.
Why explicit stash messages are underrated
Unnamed stashes are part of why people distrust the feature. Two days later, stash@{0} means nothing. A short message restores context immediately. You are much less likely to apply the wrong saved state or forget why it existed in the first place.
Final recommendation
If stash still feels like a coin flip, stop relying on the vague default memory of the command. Learn git stash push, give entries messages, and use -u when untracked files are part of the working context. The command becomes much less mysterious once your intent becomes explicit.