How to fix error: could not restore untracked files from stash in Git

GitINTERMEDIATELOWUpdated Dec 6, 2025ยท 211 views

This error occurs when running git stash pop or git stash apply and Git cannot restore untracked files because files with the same names already exist in your working directory. Git refuses to overwrite existing files to prevent data loss.

Quick fix

Fixes error: could not restore untracked files from stash

# The error message typically shows:
# error: could not restore untracked files from stash
# Already exists, no checkout: path/to/file.txt
# Already exists, no checkout: another/file.js

# List the untracked files in your stash
git stash show --include-untracked stash@{0}

# Or show only the untracked portion
git show --name-only stash^3
  1. Identify the conflicting files
  2. Option A: Delete conflicting files (if not needed)
  3. Option B: Manually extract untracked files from stash
  4. Option C: Use git stash branch
git โ€” error
# The error message typically shows:
# error: could not restore untracked files from stash
# Already exists, no checkout: path/to/file.txt
# Already exists, no checkout: another/file.js
# List the untracked files in your stash
git stash show --include-untracked stash@{0}
# Or show only the untracked portion
git show --name-only stash^3
error: could not restore untracked files from stash

What this error means

When you stash changes with `git stash -u` or `git stash --include-untracked`, Git saves both tracked and untracked files to the stash. The stash internally creates a special commit structure where untracked files are stored in a separate "third parent" commit (stash^3). When you later try to apply or pop this stash, Git attempts to restore all the stashed content. However, if any of the previously untracked files now exist in your working directory (perhaps because they were pulled from a remote branch, created manually, or generated by a build process), Git cannot safely restore them without potentially overwriting important data. Unlike tracked file conflicts that can be merged, untracked files have no merge history. Git has no way to reconcile the stashed version with the existing file, so it aborts the entire untracked file restoration while the tracked changes may partially apply.

Typical symptoms

  • git stash pop fails with 'could not restore untracked files from stash' error
  • git stash apply partially succeeds but reports errors for untracked files
  • Specific file names are listed as 'already exists, no checkout'
  • The stash remains in the stash list after a failed pop operation
  • Tracked changes from the stash may apply while untracked files do not

Common causes

  1. Files that were untracked when stashed now exist in the working directory
  2. A git pull or fetch brought in files that match stashed untracked files
  3. Build or compilation generated files that were previously stashed
  4. Another developer added files to the repository that you had stashed locally
  5. You manually created files with the same names as stashed untracked files
  6. A known Git bug (versions 2.33.1 to 2.34.x) affects untracked file restoration during rebase

How to fix "error: could not restore untracked files from stash"

1Identify the conflicting files

First, examine the error output to identify which files are causing the conflict:

bash
# The error message typically shows:
# error: could not restore untracked files from stash
# Already exists, no checkout: path/to/file.txt
# Already exists, no checkout: another/file.js

# List the untracked files in your stash
git stash show --include-untracked stash@{0}

# Or show only the untracked portion
git show --name-only stash^3

Note which files exist both in your working directory and in the stash.

2Option A: Delete conflicting files (if not needed)

If the existing files in your working directory are not needed (e.g., they're duplicates or regeneratable), remove them first:

bash
# Delete the specific conflicting files
rm path/to/file.txt another/file.js

# Now apply the stash
git stash pop

This is the simplest solution when the local files can be discarded.

3Option B: Manually extract untracked files from stash

If you need both versions, manually extract the stashed untracked files to a different location:

bash
# Show what untracked files are in the stash
git show --name-only stash^3

# Extract specific untracked files to a different path
git show stash^3:path/to/file.txt > path/to/file.txt.stashed

# Or extract to a backup directory
mkdir -p ~/stash-backup
git checkout stash^3 -- . 2>/dev/null || true
# This may fail but you can also use:
git stash show -p --include-untracked | git apply --include-untracked

# Apply tracked changes only (skip untracked)
git stash show -p | git apply

Compare the versions and manually merge if needed.

4Option C: Use git stash branch

Create a new branch from the stash's original commit, which cleanly applies all stashed changes:

bash
# Create a branch from the stash
git stash branch recovered-changes stash@{0}

# This creates a new branch at the commit where the stash was created
# and applies all stashed changes (tracked and untracked) cleanly

# Now you can merge or cherry-pick changes to your target branch
git checkout main
git merge recovered-changes
# or selectively copy files

This approach avoids conflicts entirely by restoring the exact state when the stash was created.

5Option D: Move existing files temporarily

Preserve existing files by moving them before restoring the stash:

bash
# Create a backup directory
mkdir -p ~/backup-before-stash

# Move conflicting files
mv path/to/file.txt ~/backup-before-stash/
mv another/file.js ~/backup-before-stash/

# Apply the stash
git stash pop

# Compare and reconcile files
diff ~/backup-before-stash/file.txt path/to/file.txt

This preserves both versions for manual comparison.

6Clean up and drop the stash manually

After successfully recovering your changes, clean up the stash if it wasn't automatically dropped:

bash
# Check if the stash still exists
git stash list

# If the stash is still there after applying, drop it manually
git stash drop stash@{0}

Remember: git stash pop only drops the stash if the apply succeeds completely. If there were errors, the stash remains.

Advanced notes

Understanding stash internals:

A stash with untracked files creates three commits:
- stash (or stash@{0}): The working directory state
- stash^1: The HEAD commit when stash was created
- stash^2: The index state
- stash^3: The untracked files (only exists if -u or -a was used)

You can access the untracked files directly:

bash
# List untracked files in stash
git ls-tree -r stash^3 --name-only

# View content of a specific untracked file
git show stash^3:filename.txt

# Extract all untracked files to current directory
git checkout stash^3 -- .

Known Git bug (versions 2.33.1 - 2.34.x):

There was a bug in Git versions 2.33.1 through 2.34.x where untracked files in a stash were not recovered properly during rebase operations when merge conflicts occurred. This was fixed in Git 2.35.0. If you're affected, upgrade Git:

bash
# Check Git version
git --version

# Ubuntu/Debian
sudo add-apt-repository ppa:git-core/ppa
sudo apt update && sudo apt install git

# macOS
brew upgrade git

Preventing this issue:

Consider adding commonly generated files to .gitignore to avoid stashing them:

gitignore
# Build outputs
dist/
build/
*.o
*.pyc

# Dependencies
node_modules/
vendor/

Or use git stash push with specific paths instead of -u:

bash
# Stash only specific files
git stash push -m "my changes" path/to/specific/file.txt

Alternative workflow:

Instead of stashing untracked files, consider committing them to a WIP (work in progress) branch:

bash
git checkout -b wip-feature
git add -A
git commit -m "WIP: saving progress"
git checkout main
# Later...
git checkout wip-feature

Frequently asked questions

What does "error: could not restore untracked files from stash" mean?
When you stash changes with git stash -u or git stash --include-untracked, Git saves both tracked and untracked files to the stash. The stash internally creates a special commit structure where untracked files are stored in a separate "third parent" commit (stash^3). When you later try to apply or pop this stash, Git attempts to restore all the stashed content.
How do I fix "error: could not restore untracked files from stash"?
This error occurs when running git stash pop or git stash apply and Git cannot restore untracked files because files with the same names already exist in your working directory. Git refuses to overwrite existing files to prevent data loss.
What causes "error: could not restore untracked files from stash"?
Files that were untracked when stashed now exist in the working directory A git pull or fetch brought in files that match stashed untracked files Build or compilation generated files that were previously stashed
Is the "error: could not restore untracked files from stash" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading