How to fix fatal: 'stash@{0}' is not a valid reference in Git

GitINTERMEDIATEMEDIUMUpdated Dec 6, 2025ยท 229 views

This error occurs when Git cannot locate or parse a stash reference, typically due to corrupted stash files, shell escaping issues with curly braces, or damage from git filter-branch operations. The fix involves repairing or clearing the stash.

Quick fix

Fixes fatal: 'stash@{0}' is not a valid reference

git stash list
  1. Verify the stash list and identify corrupted entries
  2. Try alternative syntax with proper quoting
  3. Recover stash commits from reflog
  4. Delete specific broken stash entries
git โ€” error
git stash list
fatal: 'stash@{0}' is not a valid reference

What this error means

When you see the error 'stash@{0}' is not a valid reference, Git is telling you that it cannot resolve the stash reference you're trying to access. The stash in Git is implemented as a special ref stored in .git/refs/stash with a reflog at .git/logs/refs/stash that tracks multiple stashed changes. This error typically means one of several things: the stash reference file has become corrupted, the reflog for the stash is damaged, or there's a shell escaping issue preventing Git from correctly parsing the curly braces in the stash syntax. In some cases, operations like git filter-branch can corrupt existing stashes, making them unreadable. The stash@{N} syntax is Git's reflog notation, where N represents the index of the stash entry (0 being the most recent). When this reference becomes invalid, you lose the ability to apply, pop, or drop that specific stash entry through normal commands.

Typical symptoms

  • Running 'git stash apply stash@{0}' fails with the fatal error message
  • The 'git stash list' command shows stashes but they cannot be applied
  • Git stash operations work inconsistently or fail unpredictably
  • Error appears after filesystem corruption, system crashes, or git filter-branch
  • CI/CD pipelines using lint-staged or similar tools fail with stash errors
  • The error message may also show as 'refs/stash@{0} is not a valid reference'

Common causes

  1. Corrupted .git/refs/stash or .git/logs/refs/stash files due to filesystem issues or interrupted Git operations
  2. Shell escaping issues where curly braces in stash@{0} are not interpreted correctly (common on Windows/MSYS2)
  3. Running git filter-branch has damaged or invalidated existing stash entries
  4. Cloud drive synchronization conflicts creating duplicate stash files like 'stash (1)'
  5. System crash or power failure during a stash operation leaving files in inconsistent state
  6. Using an outdated version of Git with known stash handling bugs

How to fix "fatal: 'stash@{0}' is not a valid reference"

1Verify the stash list and identify corrupted entries

First, check if your stashes are visible and identify which ones might be corrupted:

bash
git stash list

If this shows entries but you can't apply them, or if it produces errors, the stash reflog is likely corrupted. You can also check the raw reflog:

bash
git reflog show stash

Note any commit hashes shown - these may be recoverable later.

2Try alternative syntax with proper quoting

Shell escaping can cause issues with the curly braces in stash references. Try quoting the stash reference:

bash
git stash apply 'stash@{0}'

Or use the --index flag with a numeric argument:

bash
git stash apply --index 0

On Windows or MSYS2, you may need to escape differently:

bash
git stash apply "stash@{0}"
3Recover stash commits from reflog

Before clearing corrupted stashes, try to recover the underlying commits:

bash
git reflog stash

This may show commit hashes even if the stash reference is broken. If you see commits like abc1234 stash@{0}: WIP on main, you can apply them directly:

bash
git stash apply abc1234

Or create a branch from the stash commit to inspect it:

bash
git checkout -b recovered-stash abc1234
4Delete specific broken stash entries

If only some stashes are corrupted, you can delete them individually using reflog:

bash
git reflog delete --rewrite stash@{0}

After each deletion, run git stash list to see the updated list. The indices will shift after each deletion.

5Clear all stashes if recovery fails

If you cannot recover any stashes or don't need them, clear the entire stash:

bash
git stash clear

This removes all stash entries and should resolve the invalid reference error. You can then create new stashes normally.

6Remove corrupted stash files manually

If git stash clear doesn't work, manually remove the corrupted files:

bash
# Backup first (optional)
cp -r .git/refs/stash .git/refs/stash.backup 2>/dev/null
cp -r .git/logs/refs/stash .git/logs/refs/stash.backup 2>/dev/null

# Remove corrupted files
rm -f .git/refs/stash
rm -f .git/refs/stash.lock
rm -rf .git/logs/refs/stash
rm -f .git/logs/refs/stash.lock

After removing these files, Git will recreate them when you next run git stash. Note that this will delete any existing stashes.

7Check for duplicate or conflicting stash files

Cloud sync services can create duplicate files. Check for files like:

bash
ls -la .git/refs/stash*
ls -la .git/logs/refs/stash*

If you see files like stash (1) or stash (conflict), remove them:

bash
rm '.git/refs/stash (1)'
rm '.git/logs/refs/stash (1)'

Advanced notes

The stash mechanism in Git uses a combination of a direct reference (.git/refs/stash) pointing to the most recent stash commit, and a reflog (.git/logs/refs/stash) that maintains the history of all stash entries. When either of these becomes corrupted, stash operations fail.

If you're using git filter-branch and want to preserve stashes, consider exporting them to patches first:

bash
git stash show -p stash@{0} > stash-0.patch

For Windows users experiencing persistent shell escaping issues, consider using Git Bash instead of cmd.exe or PowerShell, or use Git's built-in stash index syntax with --index.

In CI/CD environments using tools like lint-staged that interact with stash, ensure you're using a recent Git version (1.8.5.5+) and that the CI environment properly handles shell escaping. Some tools provide workarounds or configuration options for stash-related issues.

To prevent stash corruption, avoid interrupting stash operations, ensure stable filesystem access (especially with network drives or cloud sync), and consider using branches instead of stash for important work-in-progress changes.

Frequently asked questions

What does "fatal: 'stash@{0}' is not a valid reference" mean?
When you see the error 'stash@{0}' is not a valid reference, Git is telling you that it cannot resolve the stash reference you're trying to access. git/logs/refs/stash that tracks multiple stashed changes. This error typically means one of several things: the stash reference file has become corrupted, the reflog for the stash is damaged, or there's a shell escaping issue preventing Git from correctly parsing the curly braces in the stash syntax.
How do I fix "fatal: 'stash@{0}' is not a valid reference"?
This error occurs when Git cannot locate or parse a stash reference, typically due to corrupted stash files, shell escaping issues with curly braces, or damage from git filter-branch operations. The fix involves repairing or clearing the stash.
What causes "fatal: 'stash@{0}' is not a valid reference"?
Corrupted .git/refs/stash or .git/logs/refs/stash files due to filesystem issues or interrupted Git operations Shell escaping issues where curly braces in stash@{0} are not interpreted correctly (common on Windows/MSYS2) Running git filter-branch has damaged or invalidated existing stash entries
Is the "fatal: 'stash@{0}' is not a valid reference" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading