Mar 17, 2022

[memo] git error: cannot lock ref 'refs/remotes/origin...

I often face the follwoing error when I run git fetch or git pull.

error: cannot lock ref 'refs/remotes/origin/...

How to solve?

  • git fetch --prune
  • git remote prune origin
  • git gc --prune=now
  • git remote -v
    -> copy git info(red color)
         origin  git@...git (fetch)
         origin  git@...git (push)
    -> git remote rm origin
    -> git remote add origin git@...git

  • delete the directory and clone the repogitory. <== final solution...

Why?

When we run an operation of git, it creates index.lock file inside .git directory to make sure that other git process don't take place during the operation. "error: cannot lock ref " means corruption happened in ./refs directory and cannot create index.lock



No comments: