How to fix – fatal: Unable to create ‘.git/shallow.lock’: File exists.

Today while trying to clone big repository using “git fetch” we encountered following error,

“fetching iteration / depth 2”
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 3), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (4/4), done.
Auto packing the repository in background for optimum performance.
See “git help gc” for manual housekeeping.
error: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.

fatal: Unable to create ‘/home/myuser/my_source_code/.git/shallow.lock’: File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
error: failed to run prune

Solution :

Stop git fetch command using ctrl+c

 $ rm -rf /home/myuser/my_source_code/.git/shallow.lock
 $ rm -rf /home/myuser/my_source_code/.git/gc.log

Now start “git fetch” again.

Leave a Comment