Git "refspec does not match any" on fetch in CI
A fetch named a refspec the remote does not map. Often a job tries to fetch a PR merge ref or a specific branch, but the configured fetch refspec is limited to one branch and never mirrors what you asked for.
What this error means
A git fetch origin <ref> or a push fails with fatal: refspec '<ref>' does not match any (or the fetched ref is empty). It surfaces when fetching PR refs (refs/pull/<n>/merge) on a single-branch clone.
$ git fetch origin pull/42/merge
fatal: couldn't find remote ref pull/42/merge
# or on push:
error: src refspec main does not match anyCommon causes
Single-branch clone limits the fetch refspec
A --single-branch/shallow clone configures a narrow +refs/heads/<branch> refspec. Fetching a different branch or a PR ref does not match that configured mapping.
The ref does not exist (yet) on the remote
Pushing a local branch that has no commits, or fetching a PR ref the host does not expose, leaves the refspec matching nothing.
How to fix it
Fetch the ref explicitly with a full refspec
Name both source and destination so the ref is mapped locally regardless of the default refspec.
git fetch origin +refs/pull/42/merge:refs/remotes/origin/pr-42
git checkout pr-42Widen the clone or fetch all branches
- Clone without
--single-branch, or setremote.origin.fetchto+refs/heads/*:refs/remotes/origin/*. - On GitHub Actions, set
fetch-depth: 0so all refs are available. - For pushes, confirm the local branch actually has the commits you expect.
How to prevent it
- Use a full refspec when fetching PR/merge refs.
- Avoid
--single-branchwhen the job needs other branches. - Verify the ref exists on the remote with
git ls-remotefirst.