Stash & Clean

How to Stash Untracked and Modified Files in Git

Temporarily shelve both modified and newly created untracked files to switch branches with a clean working copy.

Instant 1-Line Solution
Safe CommandBeginner
git stash -u
When to use this scenario:You are midway through developing a feature when an urgent production bug needs fixing on another branch.

Step-by-Step Execution Guide

1Stash modified & newly created untracked files
git stash -u

-u (or --include-untracked) ensures newly created files that have not yet been added are also stashed.

2Stash with a memorable name
git stash save "wip: auth login form refactor"

Gives the stash a clear description in your stash list.

3List all current stashes
git stash list

Displays all stashed entries with indices like stash@{0}, stash@{1}.

4Re-apply and remove the latest stash
git stash pop

Applies the changes back to your working copy and removes it from the stash stack.

Critical Pitfalls & Precautions

  • β€’Plain "git stash" ignores untracked files! Always use "-u" if you created new files.
Frequently Asked Questions

Stash Untracked Files - Frequently Asked Questions

Common questions about safe rollback, remote history implications, and troubleshooting.

"git stash pop" applies the changes and removes the stash from the list. "git stash apply" restores the changes but keeps the stash in the list.