Branch Does Not Exist
Error message
error: pathspec 'x' did not match any file(s) known to git
Quick summary
You referenced a branch name that git doesn't know about — it doesn't exist locally or hasn't been fetched from the remote.
Why this happens
Typo in the branch name
The branch exists on the remote but hasn't been fetched locally
The branch was deleted or never created
Minimal example
git checkout develop # error: pathspec 'develop' did not matchgit checkout dev # correct branch nameThe branch is named dev, not develop — fix the name to match an existing branch. Use git branch to list available branches.
How to diagnose
Run
git branchto list local branches — is the name there?Run
git branch -ato see all branches including remote onesCheck the spelling — branch names are case-sensitive
How to fix
Fix the typo to match an existing branch name
Run
git fetchto download remote branches, then checkoutCreate the branch with
git checkout -b <name>if it should exist
How to prevent
Use tab-completion for branch names to avoid typos
Run
git fetchbefore checking out a remote branch
Related Resources
Related Lessons
- What is Git?
Learn about Git branches
Related Practice
- Git Status Command Quiz
Test your knowledge of Git commands for inspecting branches.