git "remote error: upload-pack: not our ref" in CI
A shallow fetch requested one exact commit, but by the time the request reached the server that SHA was no longer an advertised ref, so upload-pack refuses it as "not our ref". This is typically a force-push happening between event and fetch, and a retry usually resolves it.
What this error means
A fetch of a pinned SHA fails with "fatal: remote error: upload-pack: not our ref <sha>". It appears intermittently, often only when the branch was force-pushed near the run.
fatal: remote error: upload-pack: not our ref 4b825dc642cb6eb9a060e54bf8d69288fbee4904Common causes
A force-push removed the commit mid-run
The queued run pinned a SHA; a force-push then rewrote the branch so the server no longer advertises that exact commit, and upload-pack rejects the request.
Fetching an unadvertised object by SHA
The remote only serves reachable, advertised commits by default; a SHA that is not the tip of any ref may be refused.
How to fix it
Retry the fetch
Because the cause is a timing race, retrying (or re-running) after the branch settles usually succeeds.
for i in 1 2 3; do git fetch --depth 1 origin "$SHA" && break || sleep 5; doneFetch the branch tip instead of a stale SHA
Check out the current branch head rather than a pinned SHA that may have been rewritten.
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0How to prevent it
- Avoid force-pushing branches with runs in flight.
- Retry a "not our ref" fetch; it is usually transient.
- Prefer the branch tip over a possibly rewritten SHA.