How to delete a Git repository from C#? [duplicate]

2 weeks ago 18
ARTICLE AD BOX

I have a simple Git repository:

git init test cd test echo > file git add file git commit -m "test"

I can't delete that Git repository from C# code. I tried a simple recursive delete:

Directory.Delete(@"X:\test\.git", true);

Where X: is the drive I ran above commands on. The error is:

UnauthorizedAccessException: Access to the path '<some GUID of Git>' is denied.

However, I can easily delete the .git folder from Windows Explorer (with or without recycle bin), so obviously I have enough permissions. The security tab says that I am the owner. When I check effective access for the .git folder with my user, I get a green checkmark on every item.

Advanced security settings showing full permissions

I have no console open. Virus scanner can hardly be a problem with those simple files. I tried on two different machines, which have different virus scanners.

I also tried to delete several different repositories. It happens for all of them.

How to delete a Git repository from C#?

Read Entire Article