'How to fix "Deletion of directory '.git/objects/01' failed" in git gc

I am running the command git gc on a git repository and am getting the error Deletion of directory '.git/objects/01' failed.

I am running the command in Git Bash on Windows 10.

I am pretty sure it isn't another process using the folder as I able to remove the directory within the same Git Bash shell via the rm -r command. Upon rerunning git gc I am informed Deletion of directory '.git/objects/02' failed.

Any ideas?



Solution 1:[1]

I have got the same issue in Windows 10 using git version 2.25.1.windows.1 Actually it is a test repository.

In my case all the directories with issues are empty and git asks for permission 3 times for each directory.

I solved this with:

set GIT_ASK_YESNO=false
git gc

As suggested at Unlink of file Failed. Should I try again? by andhdo. This solve the messages but leaves empty folders in disk.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user275119