Search code examples
gitpermissionsbranchfile-permissionsgit-reset

"Permission denied" error when trying to switch branches


I am trying to use git reset --hard and I get this error:

fatal: cannot create directory at '[path]/img/products': Permission denied

I have not changed permissions and everything was working correctly before. Then I try git checkout [branch name] and I get this:

error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: cannot stat '[path]/img/products': Permission denied
error: Your local changes to the following files would be overwritten by checkout:
        [path]/img/products/icons.png
        [path]/img/products/buttons.png
Please commit your changes or stash them before you switch branches.
error: The following untracked working tree files would be overwritten by checkout:
        [path]/img/leftbtn.png
        [path]/img/rightbtn.png
        [path]/img/logo.png
Please move or remove them before you switch branches.
Aborting

Everything was working correctly before and I suddenly started to experience the problems above. I simply want to switch branches. What do you recommend to try?


Solution

  • Weird. I tried again git checkout [branch name] and this time this is he error that I see:

    error: The following untracked working tree files would be overwritten by checkout:
            [path]/img/leftbtn.png
            [path]/img/rightbtn.png
            [path]/img/logo.png
    Please move or remove them before you switch branches.
    Aborting
    

    I deleted those files, tried git checkout [branch name] again, and I could switch branches successfully this time.