Sponsored

Monday, November 9, 2026

Why git stash says no local changes when you have untracked files

You created a new file, ran git stash, and received No local changes to save. The file is still there. If your tracked files are unchanged, an ordinary untracked file can explain that result.

Start by saving open editor buffers. The example below uses a repository with an existing commit, an unchanged tracked.txt, an untracked scratch.txt, and a debug.log ignored by a *.log rule. It was checked with Git 2.55.0 on Windows in a separate test repository.

1. Identify the file category

git status --short --untracked-files=all

In that example, the relevant output is:

?? scratch.txt

The two question marks identify a file outside the index. debug.log is absent from this ordinary status listing because it is ignored. An edited tracked file would have a different status. Review every listed path before deciding what should go into your stash.

The official git status reference describes the status categories. If your question is about an already staged file, use the separate unstaging walkthrough.

2. Include ordinary untracked files deliberately

git stash push -u -m "include scratch notes"

In the test, scratch.txt disappeared from the working directory after this command, while the ignored log stayed in place. The new file had moved into the stash, rather than being committed to the branch.

Review tracked modifications too: adding -u does not restrict the operation to new files. A second check with an edited tracked.txt saved both that edit and scratch.txt. This distinction matters if you intended to set aside only one part of your current work.

3. Inspect the entry before restoring it

git stash list
git stash show --include-untracked --name-only "stash@{0}"

Select the entry with your message in the list. The example uses the newest entry, stash@{0}; substitute the appropriate entry if you have made another stash since then. Including untracked files in the show command made scratch.txt visible in the tested path list.

For a content-level inspection, the stash command also supports patch output. The git stash reference documents the push, show and apply options.

4. Restore, then verify the files

git stash apply "stash@{0}"
git status --short --untracked-files=all

In the clean test state, apply restored the exact bytes of scratch.txt and retained the stash entry. The tracked-and-untracked check also restored both files. Open your files and inspect their contents after applying; an entry in the stash list alone does not verify the result.

If a file with the same name already exists, or the branch has changed, applying can fail or conflict. Read the command's output before trying another operation. Keep the stash entry while resolving and verifying your work.

What about ignored files?

git check-ignore -v -- debug.log

This identifies the matching ignore rule when the path is ignored. The check-ignore documentation explains its verbose output. The tested -u operation left debug.log unchanged; do not assume it saved every file on disk. For tracked-file ignore problems, see why .gitignore does not ignore a tracked file.

The checks above cover ordinary tracked, untracked and ignored files in a repository with a commit. They do not establish conflict recovery, submodule behavior or recovery from losing the repository itself. Keep an independent copy of work you cannot afford to lose.

No comments:

Post a Comment

Practical developer tutorials, AI tool comparisons, troubleshooting guides and free software resources.

Search This Blog

Powered by Blogger.

Blog Archive

Git troubleshooting: choose the right fix without losing work

Choose a Git command from the change you want to inspect, not from a list of commands to try. Staged edits, unstaged edits, untracked files ...