Git gives me a “Permission Denied” error when writ

2020-02-18 11:29发布

问题:

On my Windows machine, when I pull my repo I get:

error: unable to crate file <path to file> (Permission denied)

I think the problem might be that when I look at the properties of the folder there is a square inside the checkbox, I clear it out so that no files or folders will be read only.

After pressing ok and checking to see if Windows applied my changes, I see the square again!

How can I get Git or Windows to allow me to get my commits?

回答1:

Run the Git Bash or the console you are running, with Run As Administrator



回答2:

Check if another application is using your files and kill it. In my case it was grunt, always watching for the changes and building project. Gave me the same message as yours, when discarding files.

How it happened? When I've switched to another branch, some non-existent files appeared in my working copy. I could not Discard them, nor open in the text editor.



回答3:

In my situation with the same problem it was another program ( Atom ) which blocked files. Closing it helped.

So check if any other program, code editor is using the same files, if yes - turn it off.



回答4:

Adding this as for me none of the above answers worked: if you have it installed, check Bitdefender settings (or other security software you have). It operates with protected folders and might block any attempts to manipulate files. When using for example git bash, commands like rm, vim, etc., all count as separate ones and need separate permissions - not only bash.exe itself.



回答5:

I just had this kind of error after aborting a rebase. Turned out there was an orphaned git process that was keeping a lock on a file in .git directory.

Otherwise a script from this answer might also be useful.



回答6:

Turning off Windows UAC seemed to do the trick.



回答7:

Git Bash on Windows 10. The file was not read-only, so I closed the bash window and opened again and it worked.