cannot lock ref 🌿 Git

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

  1. Prune: git remote prune origin (or git fetch --prune)
  2. Delete the conflicting stale ref
  3. Remove stale .git/refs/...lock files when no git process is running

Detailed fix by platform

Git

  1. git fetch --prune origin

How to diagnose

  1. Ref — Which one?
  2. 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.