Skip to content

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

✗ Broken code
git checkout develop  # error: pathspec 'develop' did not match
✓ Fixed code
git checkout dev  # correct branch name

The 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 branch to list local branches — is the name there?

  • Run git branch -a to see all branches including remote ones

  • Check the spelling — branch names are case-sensitive

How to fix

  • Fix the typo to match an existing branch name

  • Run git fetch to download remote branches, then checkout

  • Create 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 fetch before checking out a remote branch

Related Resources

Related Glossary

Related Lessons

Related Practice

← Back to language