git ref_error ai_generated true

error: cannot lock ref: ref already exists

ID: git/cannot-lock-ref

Also available as: JSON · Markdown
85%Fix Rate
88%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

Stale lock file or conflicting ref. Common after interrupted operations.

generic

Workarounds

  1. 90% success Run git gc --prune=now to clean up stale refs
    git gc --prune=now && git remote prune origin

    Sources: https://git-scm.com/docs/git-gc

  2. 88% success Delete specific stale .lock file if present
    rm -f .git/refs/heads/branch.lock

    Sources: https://git-scm.com/docs/git-gc

Dead Ends

Common approaches that don't work:

  1. Delete .git/refs manually 80% fail

    Can corrupt repository if wrong files removed

  2. Re-clone the repository 70% fail

    Loses local branches and stashes

Error Chain

Frequently confused with: