bashgitdelete-filefuserm

Cannot remove .git: Directory not empty


Unable to remove .git

I have a git repository, Rift, that I am trying to remove. On attempting to run rm -rf, I get the error: rm: cannot remove 'Rift/.git/objects/pack': Directory not empty.

When I navigate to the bottom of the directory tree, I find a hidden file, called .fuse_hidden followed by a string of numbers and letters, possibly hexadecimal. I can manually remove this file, but as soon as I remove it, another with a different string of numbers and letters appended to it is created in it's place.

I have tried rm .git/objects/pack/* && rm -rf .git, sudo rm -rf .git, chmod -w .git/objects/path and killall git, none of which have had any success.

enter image description here


Solution

  • You can use the fuser command.

    The fuser is a command line utility intended to locate processes based on the files, directories, or a socket a particular process is accessing. It helps a system user identify processes using files or sockets.

    Use the fuser command on the .git directory, to find all of the process ids which are accessing the directory.

    fuser .git

    Afterwards you can use the -k parameter to kill the processes, and then you should be able to delete the directory.

    fuser -k .git