error: cannot lock ref 'refs/remotes/origin/x': is at … but expected … / unable to update local ref
Git couldn’t update a reference — stale remote-tracking refs, case-only branch name clashes, or a leftover lock file.
Seen on:
Git
Meaning
On case-insensitive filesystems, branches like Feature/x and feature/x collide. Deleted remote branches also leave stale refs.
Common causes
- Stale remote-tracking branches
- Case-only differences between branch names
- Leftover .lock file from a crashed process
⚡ Quick fix
- Prune: git remote prune origin (or git fetch --prune)
- Delete the conflicting stale ref
- Remove stale .git/refs/...lock files when no git process is running
Detailed fix by platform
Git
git fetch --prune origin
How to diagnose
- Ref — Which one?
- Case — Similar names differing in case?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026