Windows permission denied on switching branches

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.

4 answers

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.

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.

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.

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. 

Have you tried updating Git to the latest version?

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.

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.

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

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.

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.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Keough
Published 2 hours ago in Training & Certification

The Project Administration in Jira Server Certification is here!

The Atlassian Certification you've been waiting for is here for good. We're thrilled to announce the official launch of our new Certification for Project Administration in Jira Server! The offering ...

39 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you