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.
git stash -uStep-by-Step Execution Guide
git stash -u-u (or --include-untracked) ensures newly created files that have not yet been added are also stashed.
git stash save "wip: auth login form refactor"Gives the stash a clear description in your stash list.
git stash listDisplays all stashed entries with indices like stash@{0}, stash@{1}.
git stash popApplies 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.
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.
Related Git Command Guides
Browse All Git RecipesUndo your most recent Git commit while keeping all your edited files staged or unstaged in your working directory.
Discard all unstaged and uncommitted file modifications and restore your working tree to the latest commit.
Rename your current local branch and update the upstream remote tracking branch on GitHub or GitLab.
Delete a branch from remote origin (GitHub, GitLab, Bitbucket) after a pull request has been merged.
Amend the commit message of your latest commit before or after pushing.
Remove files from the Git staging area (index) without losing any of your local changes.