Skip to content

Instantly share code, notes, and snippets.

@metayan
Created January 18, 2026 07:03
Show Gist options
  • Select an option

  • Save metayan/233ccf0a36dc34725a19ad56da234491 to your computer and use it in GitHub Desktop.

Select an option

Save metayan/233ccf0a36dc34725a19ad56da234491 to your computer and use it in GitHub Desktop.
Fix git 'cannot lock ref' error when fetching

Problem

git fetch --all -t

gives

Fetching origin
error: cannot lock ref 'refs/remotes/origin/refactor/living-canvas-data-layer':
 'refs/remotes/origin/refactor' exists;
 cannot create 'refs/remotes/origin/refactor/living-canvas-data-layer'
From https://github.com/lem-project/lem
 ! [new branch]        refactor/living-canvas-data-layer -> origin/refactor/living-canvas-data-layer
   (unable to update local ref)
could not fetch 'origin' (exit code: 1)

Reason

A local ref refactor exists
and git is trying to fetch a remote called refactor/living-canvas-data-layer,
so it cannot create the directory refactor,
because a plain file with the same name already exists.

Solution

Delete the branch refactor, which is a stale old branch anyway.

git branch -d --remote origin/refactor
Deleted remote-tracking branch origin/refactor (was 13b60309).

Success

git fetch --all -t
Fetching origin
From https://github.com/lem-project/lem
 * [new branch]        refactor/living-canvas-data-layer -> origin/refactor/living-canvas-data-layer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment