/errors/git/pathspec-did-not-match-any-files
error: pathspec 'x' did not match any file(s) known to git
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated
- tool
- Git
- exit code
- 1
- versions
- Git 2.x
- os
- linux, macos, windows
error: pathspec 'X' did not match any file(s) known to git means git checkout X found neither a branch, tag or commit called X nor a tracked file with that path. Most often the branch exists only on the remote: run git fetch, then git switch X. If the branch should be new, create it with git switch -c X.
Reproduce it
git init -q -b main repo && cd repo
echo a > a.txt && git add a.txt && git commit -qm init
git checkout feature-loginOutput · exit 1
error: pathspec 'feature-login' did not match any file(s) known to git
Fix: fetch the remote branch
git init -q --bare origin.git
git clone -q origin.git dev 2>/dev/null && cd dev
git switch -q -c main && echo a > a.txt && git add a.txt && git commit -qm init && git push -q origin main
git switch -q -c feature-login && git push -q origin feature-login
cd .. && git clone -q -b main origin.git me && cd me
git branch -r
git fetch -q
git switch feature-loginOutput
origin/feature-login origin/main Switched to a new branch 'feature-login' branch 'feature-login' set up to track 'origin/feature-login'.
When exactly one remote has a branch with that name, git switch NAME (and git checkout NAME) creates a local branch that tracks it.
The same error for files
git add and git rm report a missing path with slightly different wording and exit status 128:
git init -q -b main repo && cd repo
git add docs/readme.mdOutput · exit 128
fatal: pathspec 'docs/readme.md' did not match any files
| Command | Meaning of the error |
|---|---|
| git checkout NAME | No branch, tag, commit or tracked file called NAME |
| git add PATH | No file at PATH (relative to the current folder) |
| git rm PATH | PATH is not tracked |
| git commit -m msg file | A path after the message does not exist or is not tracked |
Sources
Related pages
compare · gitgit switch vs git checkout: which one to usegit switch changes branches and git restore restores files; git checkout does both. Why the Git 2.23 commands are safer, with equivalents side by side.errors · gitfatal: not a git repository (or any of the parent directories): .gitGit prints not a git repository when the current folder and none of its parents contain a .git directory. cd into the repository, run git init, or set GIT_DIR.cheat sheets · gitGit cheat sheet: everyday commandsGit cheat sheet: setup, stage and commit, branches with switch, history, undo with restore, reset and revert, stash, remotes, tags and the reflog on one page.