error: pathspec 'develop' did not match any file(s) known to git — git checkout found no branch called develop in your clone, so it read the word as a file path and found no such file either. If the branch is new, create it with git switch -c develop. If a teammate pushed it, run git fetch origin first; then git switch develop creates a local branch that tracks it.

To tell the two cases apart, git branch -a lists every branch your clone knows about, local and remotes/origin/..., and git ls-remote --heads origin asks the remote directly. A branch the remote has and your clone does not is the fetch case.

The error

$ git checkout develop
error: pathspec 'develop' did not match any file(s) known to git

Exit code 1. In the same clone, git switch develop said fatal: invalid reference: develop (exit code 128).

Why it happens

git checkout does two jobs: it switches branches and it restores files. Given one word, it tries a local branch of that name, then a remote-tracking branch such as origin/develop to create a local branch from, and only then a path. The error is the last attempt failing, which is why it talks about files when you meant a branch. git switch only handles branches, so its message says what is really missing.

The remote case confuses people because the branch plainly exists on GitHub. A clone knows the remote's branches only as of its last fetch. The teammate pushed develop after this clone was made, so the clone had never heard of it, while the remote listed it:

$ git branch -a
* main
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
$ git ls-remote --heads origin
7c6f47204bf6af0506710e0cbd7a7aea7c822618	refs/heads/develop
f4949b08d2e7c56e8c3fe108295a2768085ae36a	refs/heads/main

The fix

When develop exists nowhere yet, create it and, if others need it, publish it:

$ git switch -c develop
Switched to a new branch 'develop'
$ git push -u origin develop
branch 'develop' set up to track 'origin/develop'.
To .../origin.git
 * [new branch]      develop -> develop

When it exists on the remote, fetch first, then switch:

$ git fetch origin
From .../origin
 * [new branch]      develop    -> origin/develop
$ git switch develop
branch 'develop' set up to track 'origin/develop'.
Switched to a new branch 'develop'
$ git status -sb
## develop...origin/develop

The fetch adds remotes/origin/develop to the clone, and the switch creates a local develop on the same commit with origin/develop as its upstream, so later pulls and pushes need no arguments. Once the remote branch is known, git checkout develop works too: a fresh clone made after the push ran it and printed the same two lines as the switch above.

How it was reproduced

Git for Windows 2.45.2 (git version 2.45.2.windows.1) in Git Bash 5.2.26. A local bare repository stood in for GitHub; its absolute path in the To and From lines is shortened to .../origin.git, nothing else changed. Two clones were made while the remote had only main. In the first, develop existed nowhere, so both commands failed; it then created the branch with one commit and pushed it. The second clone, not fetched since it was made, failed the same way until git fetch origin. The personal global config was replaced by an empty file (GIT_CONFIG_GLOBAL) so no personal setting could change the result.

Frequently asked

Why does git checkout say pathspec did not match any file(s) known to git?
Git found no local branch with that name and no remote-tracking branch to create one from, so it treated the name as a file path and found no such file. The branch does not exist in your clone yet.
How do I check out a remote branch that git does not see?
Run git fetch origin so your clone learns about the new branch, then git switch develop or git checkout develop. Git creates a local branch that tracks origin/develop.
What is the difference between git switch and git checkout?
git switch only changes branches, so a missing branch gives fatal: invalid reference. git checkout also restores files, so a name that is neither a branch nor a file gives the pathspec error.

More decoded errors in the Fixes category. Remotes, fetch and pull are Part 6 of the Git series, GitHub: Your Code in the Cloud.