Cannot Lock Ref
Error message
fatal: cannot lock ref 'refs/heads/feature': unable to resolve reference
Quick summary
A reference lock could not be acquired — usually due to a stale lock file or a corrupted ref state.
Why this happens
A previous Git operation was interrupted, leaving a stale lock file
Another Git process is running simultaneously on the same repo
The .git directory has corrupted ref files
Minimal example
git checkout feature # fatal: cannot lock ref 'refs/heads/feature'# Remove stale lock file
rm .git/refs/heads/feature.lock
git checkout feature # now succeeds
# Or clean up with gc
git gc
git checkout featureRemove the stale .lock file left by an interrupted operation, then retry the command.
How to diagnose
Check for lock files: ls .git/refs/heads/ and look for .lock files
Verify no other Git processes are running
Run git gc to clean up and pack refs
How to fix
Remove stale lock files: rm .git/refs/heads/<branch>.lock (use with caution)
Run git gc to clean up the repository
If corrupted, re-clone the repository from the remote
How to prevent
Avoid running multiple Git operations simultaneously on the same repo
Do not interrupt Git operations mid-execution