error: pathspec 'x' did not match any file(s) known to git — how to fix
error: pathspec 'x' did not match any file(s) known to git
Quick fix: For a branch: git fetch origin then git switch branch-name. For a file: check the path and case with git ls-files | grep name.
What it means
Git interpreted what you typed as a pathspec (a file or branch name) and found nothing matching it.
Case 1: checking out a branch
git checkout feature-x
# error: pathspec 'feature-x' did not match any file(s) known to git
The branch probably exists only on the remote and your local repo hasn't heard of it yet:
git fetch origin
git branch -a | grep feature-x
git switch feature-x # creates a local branch tracking origin/feature-x
If you cloned with --depth 1 or --single-branch, other branches aren't fetched. Fix with:
git remote set-branches origin '*'
git fetch origin
Case 2: a file
- Check spelling and case:
README.md≠readme.md. - Paths are relative to your current directory.
git rm/git checkout -- fileonly work on files Git tracks. List them:git ls-files | grep name.
Case 3: commit messages on Windows
git commit -m 'my message' # in cmd.exe, single quotes aren't quotes!
cmd.exe splits that into 'my and message', and Git treats the second word as a file. Use double quotes: git commit -m "my message".
Last updated 2026-10-27.