pathspec did not match any files — How to fix it
This Git error means the file or branch you referenced does not exist, is not tracked, or has a typo. Here is how to find and fix the problem.
What this error means
When Git says error: pathspec 'file' did not match any file(s) known to git, it means it looked through its index and branch list and could not find anything matching the name you provided.
A pathspec is simply the file path or branch name you pass to a Git command. If that name doesn't match a tracked file, an existing branch, or a valid path, Git gives up and shows this error.
The good news: this error never causes data loss. It's Git telling you "I can't find what you're looking for" before doing anything.
Why it happens
Typo in the filename or branch
The most common cause. You typed feture instead of feature, or forgot a directory in the path. Git matches names exactly — there is no fuzzy search.
File not tracked by Git
If you created a new file but never ran git add, Git does not know about it. Commands like git checkout or git stash cannot find untracked files.
Case sensitivity mismatch
Linux treats App.js and app.js as different files. macOS and Windows do not. Cross-platform teams often run into this when filenames were committed with different casing.
How to fix it
Follow these steps to find the mismatch and resolve the error.
1. Check with git status
2. Add or fetch the target
3. Fix case sensitivity
How to prevent it
Use tab completion
Type the first few characters of a file or branch name and press Tab. Your shell will auto-complete the name or show you the available options. This eliminates typos.
Run git status first
Before running destructive or complex commands, run git status to see exactly which files are tracked, modified, and untracked. It takes one second and saves debugging time.
Agree on naming conventions
Use lowercase filenames and kebab-case branch names across your team. This avoids case sensitivity surprises when collaborators work on different operating systems.
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
FAQ — pathspec did not match
Stop guessing, start understanding Git
GitQuest teaches you Git through hands-on practice so error messages make sense.
Start learning Git