GrepBoard/Manuals
605 manuals ·

Fix error: pathspec did not match any file(s) known to git

·Tested on Ubuntu 24.04 (Docker) · git 2.43.0 · 2026-10·Test scope ↓·6 steps

error: pathspec did not match any file(s) known to git means no branch or file has that name. Check unfetched branches, case, shallow clones, cmd quotes.

output
error: pathspec 'fix-typo' did not match any file(s) known to git

When git checkout <name> can't resolve the name as a branch, it retries it as a file path (a pathspec), and when that fails too you get this error. If you were switching branches, the usual causes are a remote branch you haven't fetched yet, a letter-case mismatch, or a shallow clone that only tracks one branch. If it came from git commit -m, it's single quotes in the Windows Command Prompt.

[1] Check whether you have fetched the remote branch. A branch a teammate just created is unknown locally until git fetch. git switch words the same failure differently.

console
$ git checkout fix-typoerror: pathspec 'fix-typo' did not match any file(s) known to git$ git switch fix-typofatal: invalid reference: fix-typo$ git branch -r  origin/HEAD -> origin/main  origin/feature-login  origin/main

If the branch is not in git branch -r, fetch. Afterwards the same command creates a local branch that tracks the remote one.

console
$ git fetch originFrom /srv/remote * [new branch]      fix-typo   -> origin/fix-typo$ git checkout fix-typoSwitched to a new branch 'fix-typo'branch 'fix-typo' set up to track 'origin/fix-typo'.

[2] Match the name exactly. Branch names are case-sensitive. Ask the server directly to see which names really exist.

console
$ git checkout main && git checkout Feature-LoginSwitched to branch 'main'Your branch is up to date with 'origin/main'.error: pathspec 'Feature-Login' did not match any file(s) known to git$ git ls-remote --heads origin342560e91c3fcc578a0b9dd9c71b822c3e8a5f59	refs/heads/feature-login1ff58fdcb716367e8031c359aa3aa01ac9bad658	refs/heads/fix-typodd7f4d6c2109b7333647f76452497edb37aa4fcf	refs/heads/main

git ls-remote lists the remote's current branches without fetching. If a branch shows up here but not in git branch -r, you're in [1] or [4].

[3] Pick a remote when more than one has the branch. In fork workflows, origin and upstream often share branch names, and the automatic tracking branch is not created.

console
$ git checkout feature-loginhint: If you meant to check out a remote tracking branch on, e.g. 'origin',…fatal: 'feature-login' matched multiple (2) remote tracking branches$ git switch -c feature-login --track origin/feature-loginSwitched to a new branch 'feature-login'branch 'feature-login' set up to track 'origin/feature-login'.

To always prefer origin, set git config checkout.defaultRemote origin (it applies to git switch too).

[4] Widen the fetch refspec in a shallow clone. git clone --depth 1 implies --single-branch, so every later git fetch brings only the default branch.

console
$ git config --get-all remote.origin.fetch+refs/heads/main:refs/remotes/origin/main$ git fetch origin && git branch -r  origin/HEAD -> origin/main  origin/main$ git checkout feature-loginerror: pathspec 'feature-login' did not match any file(s) known to git

The giveaway is that origin/main is still the only remote branch after a fetch. Track all branches and fetch again.

console
$ git remote set-branches origin '*' && git fetch -q --depth 1 origin && git checkout feature-loginSwitched to a new branch 'feature-login'branch 'feature-login' set up to track 'origin/feature-login'.

If you need just one branch, add only that one: git remote set-branches --add origin feature-login. That only changes what gets fetched — it does not fetch the branch — so follow it with git fetch origin (add --depth 1 for a shallow clone) and run git checkout feature-login again.

[5] If it came from git commit -m, switch to double quotes. Windows cmd.exe does not treat single quotes as grouping, so git commit -m 'fix typo' reaches git as two arguments, -m "'fix" and "typo'". The second is read as a file path to commit. The command below passes exactly those arguments.

console
$ git commit -m "'fix" "typo'"error: pathspec 'typo'' did not match any file(s) known to git

In cmd.exe, write git commit -m "fix typo". PowerShell and Git Bash group single quotes correctly. A stray ' at the end of the name in the error ('typo'', 'commit'') points to this case.

[6] If you were working with files, check the path. git add and git rm print a similar message starting with fatal:.

console
$ git add docs/guide.mdfatal: pathspec 'docs/guide.md' did not match any files$ git ls-files docsdocs/Guide.md$ touch notes.txt && git rm notes.txtfatal: pathspec 'notes.txt' did not match any files
CommandWhat the message means
git add <path>The path doesn't exist in the working tree (case counts)
git rm <path>Git isn't tracking the file — delete it with plain rm
git checkout -- <path>The path isn't in the index

In scripts, add --ignore-unmatch so a missing file doesn't stop the run, for example git rm --cached --ignore-unmatch <path>. It exits with 0.

If the push is then rejected with ! [rejected], see Fix git push rejected.

Official references: git-checkout — --guess, checkout.defaultRemote · git-switch · git-clone — --depth, --single-branch · git-remote — set-branches · gitglossary — pathspec

#git#git-checkout#git-switch#pathspec