git: 'error: cannot lock ref' / 'unable to update local ref' on fetch or pull
A stale remote-tracking ref conflicts with a new branch name (for example a remote branch feature was deleted and feature/x now exists), or a case-only rename collided on a case-insensitive filesystem. Run git remote prune origin (or git fetch --prune) to drop stale refs, then fetch again. If a lock file was left by a crashed git process, delete the named .lock file under .git.
The directory/file case shows up as e.g. "'refs/remotes/origin/feature' exists; cannot create 'refs/remotes/origin/feature/x'", and git fetch --prune fixes it in one step. If only one ref is bad, git update-ref -d refs/remotes/origin/<name> removes just that one. Before deleting a .lock file, make sure no git process (IDE, GUI client, background fetch) is still running, or you can corrupt an in-progress write.