Question

All of a sudden, I started receiving the following error when checking out my local master branch. The problematic file, as well as the error itself, appears to be random (sometimes the checkout works perfectly fine).

"c:\Program Files (x86)\Git\bin\git.exe" checkout --merge "master"
D   abc123.cs
error: unable to create file abc123.cs (Permission denied)
Switched to branch 'master'
Done
Was it helpful?

Solution 5

Daniel Hilgarth's anti-virus suggestion in the comments reminded me that I had run (and prematurely canceled) file recovery scans shortly before the problem manifested.

It's possible these scan processes were causing the problem if they didn't cancel properly.

Regardless, rebooting my machine fixed the issue.

OTHER TIPS

Just closing the editor solved my issue. By the way, I was using Atom editor.

I don't know if you're using sublime text, but when I got the permission denied problem, I noticed there was a license notice popup; that tries to get you to donate to sublimetext3 every once in a while.

Once I closed that popup and ran the commands again, the denied permission errors went away and everything worked fine.

I extrapolate that other editors with popup notices may cause this issue.

Rebooting, as bugged87 mentioned, would certainly get rid of any popups or notifications.

The same happened with me a time ago and I've closed my VScode, typed git checkout and it worked!

In my case, my angular app was still running from ng serve, giving this:

Git Bash - ng serve

So I just had to close it with ctrl+c.

Closing my text editor (Atom) fixed it.

For me, the solution is to open Windows Task Manager and kill any IIS running instance.

Close VSCode and run git checkout master -f worked for me.

Same problem on Cmder console; I just closed it and it did the trick.

Closing all of my open sessions and starting a fresh one worked for me.

This is a mistake in the OS level and does not relate to Git!

Sometimes the issue was resolved by closing the IDE and all the explorers, and sometimes it was solved by rebooting.

But the best solution is to create another folder and clone the project in it. You can also delete old project after cloning. You would not see any permission denied issue in the new folder.

You could try closing VS Code Editor and Git Bash; then again opening Git Bash and running below command.

git checkout branch-name

I just faced the same problem on Win7.

For me the solution was to disable the RealTime Protection in Microsoft Security Essentials while doing the git checkout master

Just keep in mind to turn it back on again.

Rebooting is probably not necessary. You can try closing your editor or IDE and exiting from all your CMD or Windows shell, currently set into that project folder.

Just closing the Visual Studio Code editor solved my issue.

A heads up that the preview pane in Windows Explorer can also cause permissions errors. I just spent an hour trying to hunt down what was causing the issue, thinking it was some kind of file corruption, when it suddenly became clear that as long as the preview pane was closed (or else that the file in question was not selected in the file explorer) then everything was fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top