Skip to content
Latchkey

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 output
$ 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 any

Common 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.

Terminal
git fetch origin +refs/pull/42/merge:refs/remotes/origin/pr-42
git checkout pr-42

Widen the clone or fetch all branches

  1. Clone without --single-branch, or set remote.origin.fetch to +refs/heads/*:refs/remotes/origin/*.
  2. On GitHub Actions, set fetch-depth: 0 so all refs are available.
  3. 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-branch when the job needs other branches.
  • Verify the ref exists on the remote with git ls-remote first.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →