Git: error: pathspec did not match any file(s) known to git
A plain-words explanation of this Git message: what it means, the usual causes, and the steps that fix it.
The messageerror: pathspec 'feature-login' did not match any file(s) known to git
Make the error yourself
Run with git version 2.56.0.windows.4. This is the smallest example we could find that shows it.
Setup used before these commands (a practice folder with no data)
export GIT_AUTHOR_NAME=Asha GIT_AUTHOR_EMAIL=a@example.com GIT_COMMITTER_NAME=Asha GIT_COMMITTER_EMAIL=a@example.com
git init -q -b main
echo 1 > f.txt
git add f.txt
git commit -qm firstCommands
git checkout feature-loginGit prints (the real message)
error: pathspec 'feature-login' did not match any file(s) known to gitWhy it happens
Many Git commands accept a name that could be a branch, a file or a commit, and the part of Git that looks for it is called the "pathspec". The message says that it found nothing that matches. When you run git checkout name Git looks for a branch with that name, then for a file with that name. If neither exists you get this error. The causes are a typo, a branch that exists only on the server and has not been fetched yet, a branch that has a different capitalisation, or (with git add) a file path that is wrong or in another folder.
How to fix it
- List the branches that you have:
git branch, and those on the server:git branch -r. - If the branch is on the server, download the list first with
git fetch, thengit switch feature-login. - If you want to create a new branch, add
-b:git checkout -b feature-login, orgit switch -c feature-login. - For
git add, check the path withlsorgit status. File names are case sensitive on Linux and Mac.
The corrected version
Commands
git checkout -b feature-loginGit prints (the corrected version)
Switched to a new branch 'feature-login'How to avoid it
Use tab completion in your terminal: it completes branch and file names and shows spelling mistakes immediately.
Questions
What is the difference between git checkout and git switch?
git switch changes branches only, and git restore restores files. git checkout does both, which is why it is more confusing. The newer commands are clearer.
This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.