Windows permission denied on switching branches

Christopher Froehlich August 24, 2014

As of SourceTree 1.6.3, when I switch between branches across which file system file and/or folder renames have been performed (e.g. /src/Car/* has been moved to /src/Vehicle/*) or even a simple set of renames within the same folder (e.g. all /src/Car/ files get renamed from Car<name> to Vehicle<name>) I get a series of:

git -c diff.mnemonicprefix=false -c core.quotepath=false checkout <branchname>

error: cannot stat 'src/Car': Permission denied

errors. In addition the location itself becomes inaccessible via the filesystem. The /src/Car folder is unreadable, showing a "You must have Read permissions to view the properties of thos object. Click Advanced to continue." All subsequent operations in File Explorer result in the same error. No amount of fiddling seems to unlock the folder in question.

A reboot resolves the matter. Switching between branches immediately works as expected.

7 answers

18 votes
Scott Guymer March 16, 2015

I banged my head against this for a while and it seems to be permissions based at first so i tried

  • adding the permissions - no dice
  • changing the owner - no dice
  • deleting the folder - no dice
  • deleting the folder in a million different ways! - no dice

it was always coming back with access denied and when you looked it wouldn't show you anything about the folder at all - no permissions no owner it was like it was corrupt or something.

Then i saw some of the comments above and closed everything on my machine - sourcetree, visual studio, explorer and reopened and it was then visible.

 

Something had locked the file down tight and wasn't letting anything in. It seemed to happen off the back of a failed pull for me.

 

My approach in future will be to shut down all applications possibly involved with the file and or reboot and then try and gain access.

Cathy Sullivan February 2, 2016

I did all this and rebooted the machine. Fixed the problem. I think I've seen this before and was looking for a "real" solution other than a MS operating system confution. Reboot is my friend. Thanks.

Like # people like this
Ivan Golovic November 19, 2020

Thanks. Exact process that locks folder can be found easily using Process Explorer - Find (free tool by Sysinternals):

p-denied.png

17 votes
joelmez4 March 12, 2018

I have been with the same problem, and the way that I figure out was restart my code editor closing all files related to the project (Atom) and my git GUI (SourceTree). After that, you can change the Branch.

Rajashekhar July 23, 2018

It worked for me. thanks a ton @joelmez4

Like joelmez4 likes this
anderson_rubio August 29, 2018

Thanks! I just had to close Atom and retry again.

Like # people like this
rodcalvin March 21, 2019

Thanks for the help

Dhyani Rawal April 8, 2019

It works thanks Joel Meza

Like joelmez4 likes this
Cloppi August 14, 2019

Thanks @joelmez4 ! I found that I got few files opened in Atom. Just closed it and the switching had been made with no errors :)

Like joelmez4 likes this
Gabriela Soto September 6, 2019

Thanks @joelmez4

Like joelmez4 likes this
Paul Hoffrichter June 5, 2020

I checked out master to do a git pull. Got errors about uncommitted files, so I did a git stash. After doing a git pull, I tried to get back to working branch. No luck. I had also done a git pop - no luck. I tried many attempts from here:

https://appuals.com/how-to-fix-git-error-you-need-to-resolve-your-current-index-first/

No luck.

Then I closed MATLAB, gitk, SourceTree, git bash, Windows Explorer - maybe more than necessary.

Brought up git bash, and checkout to my working branch worked.

Did a git pop and my files were restored.

Thank you for the simplest, and for me, the only working solution. :)

I guess reboot would also work, but  this solution is less painful as it only affects the folder in question.

Like joelmez4 likes this
2 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 31, 2014

Check (and maybe recursively reset) the Windows file/folder permissions for the root folder of the clone. Preferably, you should have administrator/owner privileges for this folder an all of its descendants.

Also, I have seen a similar problem with old versions of msysgit, so if you are not using the embedded Git in SourceTree (you can check in Tools\Options\Git), update msysgit to the latest version from here.

Juan Vidal Pich January 11, 2015

I have this same problem when changing branches. So far I could only discover that the problem is not related to permissions, but those directories which are inaccessible are locked by the Windows Explorer.

If I search for processes holding the file handles for this dirs (in tools such as Process Hacker), it invariably returns Explorer. After forcing those handles to close I regain access. But then SourceTree detects many ficticious modifications, which I have to reset. 

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2015

Have you tried updating Git to the latest version?

Juan Vidal Pich January 12, 2015

Yes, I'm using version msysGit 1.9.5. Git-cheetah is definitely one suspect, but I have so many shell integrations from different software packages that isolating the culprit won't be easy. I did notice, while tracking the locks, that there seem to be many open handles pointing to directories.

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2015

Since the process locking the files is Explorer, the culprit is probably one of the shell integrations. You could try switching off/uninstalling all of them and switching them back on one by one to see which one makes it go wrong again.

Oliver Dungey May 18, 2016

Thanks for the clue - I was continually getting locked up folders when switching branches and it was driving me nuts. When I investigated I had GIT 1.9.5 preview installed, just upgraded to 2.8.2 and rebooted and I can now switch branches without lockup.

As an aside - I think the files and folders are locked by virtue of crashed/locked git processes, killing them off got rid of the permission denied errors.

1 vote
ashvini_citrusbug July 2, 2019

I was having the same problem of permission denied on file while using git commands.
I just closed all the code editors, terminals and after reopened it was worked.  

0 votes
maryleitner January 27, 2020

I couldn't "git pull" or switch branches.  Closing Windows Explorer solved the problem

0 votes
Natalia Galant May 10, 2018

Hey, I had the same problem but got this workaround to work. I first got the error when I did this 

git checkout develop
merge --no-ff my_local_branch

and it continued to show up when trying to 

git checkout my_local_branch

not sure if anyone has found a solution but in order to regain access to your files you can push the local branch without checking it out 

git push origin my_local_branch:my_local_branch

 Check bitbucket or github (whichever you are using) to make sure your branch has been pushed. Afterwards you can clone your repo into a different location (I did this in a new folder on the C drive, outside of the Users directory and it worked). I got the files back by 

git fetch && checkout my_local_branch

Then.........

  • Try to delete the original corrupt files  in admin mode
  • if access is denied, reboot machine and the deletion should complete 
  • git pull
  • git fetch && checkout my_local_branch
0 votes
chris del April 4, 2018

Has anyone figured out a solution to this? Restarting the text editor (Atom for me) is not a valid solution. But as of now this is all that allows me to changes branches.

chris del May 7, 2018

Does this issue help me solve the issue? Or are U still having the problem? Looks like Atom doesn't know what it is. It is still happening to me and so I'm moving over to VSC because of this issue.

byronigoe May 13, 2018

@chris del Did you read the issue I linked? I tracked down the bug in Atom, and submitted a PR which was merged. A simple workaround is to create the "recovery" directory.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events