The Exact Error
error: pathspec 'feature/my-branch' did not match any file(s) known to git
Quick summary: Git can't find what you specified — either the branch name doesn't exist locally (needs a
git fetch), the file path is wrong or untracked, or there's a typo. The phrase "known to git" is the key — Git only knows about branches it has fetched and files it has tracked.
Why This Error Happens
Git looks through local branches, tags, remote-tracking refs, and paths in the working tree. If none match, you get this error.
Five common causes:
1. Branch exists on remote but not fetched locally — Someone created it and you haven't run git fetch.
2. Typo in branch or file name — Single character difference or wrong case.
3. Untracked file — git checkout -- file.js when file.js was never git added.
4. Wrong path separator — Using backslash on Windows instead of forward slashes.
5. Stale remote ref — Branch was deleted on the remote but your local refs are outdated.
Step-by-Step Diagnosis
Step 1 — Check if the branch exists locally
git branch # List all local branches
git branch | grep feature
Step 2 — Fetch and check remote branches
git fetch origin
git branch -r # List remote branches
git branch -a # All local + remote
Step 3 — Check for typos with tab completion
git checkout feature/<TAB> # Shows available branches
git branch -a --sort=-committerdate | head -20
Step 4 — For file checkout, check if it's tracked
git ls-files src/myfile.js # Returns path if tracked, empty if not