#StackBounty: #windows-10 #git Why does Git for Windows create repositories that I can't delete from a command line?

Bounty: 50

I have freshly “Reset” installation of Windows 10. I installed the “Git for Windows” distribution of Git from https://git-scm.org/.

If I create a git repository in any way (whether init or clone), that repository can’t be deleted from my file system with a command line prompt. I have to use Windows Explorer to do it.

Here’s a sample session:

PS C:Usersradix> mkdir foo


    Directory: C:Usersradix


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        5/10/2018   5:46 PM                foo


PS C:Usersradix> cd foo
PS C:Usersradixfoo> git init .
Initialized empty Git repository in C:/Users/radix/foo/.git/
PS C:Usersradixfoo> cd ..
PS C:Usersradix> rm foo -Recurse
rm : Cannot remove item C:Usersradixfoo.git: You do not have sufficient access rights to perform this operation.
At line:1 char:1
+ rm foo -Recurse
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (.git:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
rm : Directory C:Usersradixfoo cannot be removed because it is not empty.
At line:1 char:1
+ rm foo -Recurse
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:Usersradixfoo:DirectoryInfo) [Remove-Item], IOException
    + FullyQualifiedErrorId : DirectoryNotEmpty,Microsoft.PowerShell.Commands.RemoveItemCommand

This is PowerShell running as my normal user. Even if I run Powershell as an administrator, the rm -Recurse command still fails in the exact same way. The only way I know of to delete this new foo directory is to do it via Windows Explorer, which doesn’t even complain or prompt about permissions – it just silently deletes it with no problem.

Also, the same happens with the Command Prompt instead of powershell, so this isn’t a PowerShell-specific issue.

It’s important to note that the rm command does delete the files from the repository, including the files inside the .git directory. But it leaves the .git directory there.

So I have two questions: why can’t I delete this folder, and why is git creating it in a way that it can’t be deleted in the first place?


Get this bounty!!!

Leave a Reply