git workflow_error ai_generated true

No local changes to save — git stash fails when only untracked files exist

ID: git/stash-no-local-changes

Also available as: JSON · Markdown
95%Fix Rate
94%Confidence
85Evidence
2017-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

By default, 'git stash' only saves tracked files with modifications and staged changes. Untracked files (new files never added to git) and ignored files are NOT stashed. Developers create new files, try to stash to switch branches, and get 'No local changes to save' because git doesn't see untracked files as local changes.

generic

Workarounds

  1. 97% success Use git stash -u (--include-untracked) to stash untracked files
    Run 'git stash -u' or 'git stash push --include-untracked'. This saves tracked modifications AND untracked files. The untracked files are removed from the working directory and stored in the stash. Recover with 'git stash pop' as usual.

    Sources: https://git-scm.com/docs/git-stash

  2. 95% success Use git stash -a (--all) to also include ignored files
    Run 'git stash -a' or 'git stash push --all'. This saves everything: tracked modifications, untracked files, AND ignored files. Be careful with -a as it can stash large build artifacts, node_modules, etc. which makes stash operations slow.

    Sources: https://git-scm.com/docs/git-stash

  3. 93% success Use git stash push with pathspec for selective stashing
    Run 'git stash push -m 'description' -- path/to/file1 path/to/file2'. This stashes only specific files. Combine with -u for untracked files: 'git stash push -u -- newfile.py'. Use 'git stash list' to see all stashes with their messages.

    Sources: https://git-scm.com/docs/git-stash

Dead Ends

Common approaches that don't work:

  1. Running git stash expecting it to save new (untracked) files 90% fail

    Plain 'git stash' only captures changes to tracked files (modifications and staged changes). New files that have never been 'git add'-ed are untracked and invisible to stash. You'll lose the ability to switch branches cleanly since the untracked files remain in the working directory.

  2. Using git stash pop when you meant git stash apply 55% fail

    git stash pop applies the stash AND removes it from the stash list. If the apply has conflicts, the stash is NOT removed (safe). But if it applies cleanly, the stash is gone. Use 'git stash apply' to keep the stash entry as a safety net, then 'git stash drop' after confirming the changes are correct.

  3. Running git stash while in the middle of a merge or rebase 80% fail

    During an in-progress merge or rebase, 'git stash' may fail or produce unexpected behavior. The merge/rebase state is stored in .git/MERGE_HEAD or .git/rebase-merge/ and stash doesn't preserve this state. Complete or abort the current operation before stashing.

Error Chain

Leads to:
Frequently confused with: