Skip to content
Latchkey

Git "remote error: upload-pack: not our ref" on Fetch in CI

You asked the remote to send a specific commit SHA, and the remote no longer advertises it. A force-push or a gc removed that object, so the server refuses to serve a ref it does not consider reachable.

What this error means

A git fetch origin <sha> fails with fatal: remote error: upload-pack: not our ref <sha>. Branch fetches work; only the pinned commit is rejected - usually a PR head SHA that was rebased or force-pushed.

git fetch output
fatal: remote error: upload-pack: not our ref 9fceb02d0ae598e95dc970b74767f19372d61af8

Common causes

The commit was force-pushed away

A PR head or branch was rebased/force-pushed after the SHA was captured. The old commit is no longer reachable from any ref, so the server will not serve it by SHA.

Fetching an arbitrary SHA the server will not advertise

By default a server only serves SHAs reachable from advertised refs (uploadpack.allowReachableSHA1InWant). A dangling or gc’d object is rejected as "not our ref".

How to fix it

Re-resolve the current head SHA

Look up the ref that should contain the commit and fetch that, rather than a stale captured SHA.

Terminal
git ls-remote origin refs/pull/42/head
git fetch origin refs/pull/42/head

Fetch the branch/PR ref instead of a bare SHA

  1. Re-read the event payload for the up-to-date head SHA before fetching.
  2. Prefer fetching the named ref (refs/pull/<n>/merge or a branch) so a force-push does not strand you.
  3. If you must pin a SHA, fetch it immediately after capture, before it can be rewritten.

How to prevent it

  • Fetch named refs, not captured SHAs, when a branch may be force-pushed.
  • Re-resolve the head SHA from the current event payload at fetch time.
  • Avoid caching a PR head SHA across long-running queued jobs.

Related guides

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