git
ref_error
ai_generated
true
error: cannot lock ref: ref already exists
ID: git/cannot-lock-ref
85%Fix Rate
88%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2 | active | — | — | — |
Root Cause
Stale lock file or conflicting ref. Common after interrupted operations.
genericWorkarounds
-
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
-
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:
-
Delete .git/refs manually
80% fail
Can corrupt repository if wrong files removed
-
Re-clone the repository
70% fail
Loses local branches and stashes
Error Chain
Frequently confused with: