Skip to content

/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

bash
git init -q -b main repo && cd repo
echo a > a.txt && git add a.txt && git commit -qm init
git checkout feature-login

Output · exit 1

error: pathspec 'feature-login' did not match any file(s) known to git

Fix: fetch the remote branch

bash
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-login

Output

  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:

bash
git init -q -b main repo && cd repo
git add docs/readme.md

Output · exit 128

fatal: pathspec 'docs/readme.md' did not match any files
CommandMeaning of the error
git checkout NAMENo branch, tag, commit or tracked file called NAME
git add PATHNo file at PATH (relative to the current folder)
git rm PATHPATH is not tracked
git commit -m msg fileA path after the message does not exist or is not tracked

Sources