Fixes · Checked on 2026-10-07, with git 2.55
error: cannot lock ref 'refs/remotes/origin/main'
Two fetches in one repository at the same time. Fetch again.
The error
$ git fetch origin
error: cannot lock ref 'refs/remotes/origin/main': is at 880dd2bc80cfabddec339973e92aee00044b8b11 but expected 9ff6770542ff7a568cd442af02d10db723dd00ba
From github.com:you/app
! 9ff6770..880dd2b main -> origin/main (unable to update local ref)
git pull fetches first, so it fails the same way.
Why it happens
A fetch notes where origin/main points, downloads what's new, and then moves the ref only if it
still points there. When another fetch moved it in the meantime, git refuses: the ref is at the new
commit, but this fetch expected the old one.
Separate clones have their own refs, but every worktree of a clone shares them. So agents working in their own worktrees still race when they fetch at the same moment, and so does an editor that fetches in the background. In our test, two worktrees fetching together, each time just after a push, failed 28 times in 30.
The fix
Nothing is broken. The other fetch already moved origin/main to the new commit: in our test it
matched the remote after every failed round. Fetch again, and it succeeds.
In a script, retry once:
git fetch origin || { sleep 2; git fetch origin; }
In PowerShell:
git fetch origin; if ($LASTEXITCODE) { Start-Sleep 2; git fetch origin }
core.filesRefLockTimeout doesn't help: it makes git wait for a lock another process holds, and
here nothing holds it, the ref has simply moved. With a 3-second timeout, 25 of 30 rounds still failed.
To see it less often, fetch from one place at a time: let one agent fetch for the others, and turn off the editor's automatic fetch in a repository agents work in.
How DMN learned it
It came up, and was fixed, in 2 of our own sessions. DMN kept the fix as one line:
If `git fetch` fails with "cannot lock ref 'refs/remotes/origin/main'", a concurrent session's fetch on the
shared repo raced it; just rerun `git fetch` (optionally after `sleep 2`).
DMN reads your agents' past sessions on your machine. When the same error is fixed the same way in two or more of them, it keeps the fix as a one-line lesson. When the error turns up again, Claude Code is told the fix straight away, and any agent can search what earlier sessions found. How DMN keeps what agents learn.