Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout error: cannot create directory: Permission denied

I am facing issues with the git checkout command. Please help.

Here is what I did.

  1. Created a local directory. Created some files. Initiated a git repo locally.
  2. Created a repo in bitbucket & pushed my local repo to bitbucket
  3. Created a new branch locally, b01
  4. Added new files to b01, committed them and successfully pushed the branch to bitbucket
  5. Now I am trying to merge b01 with master and that is where I am facing issues. I am not able to checkout master.

Lists of commands used and the error details:

git clone [my repo] git checkout -b b01 

Hereafter I made multiple changes, including creating new files and directories, committed those changes and successfully pushed the changes on that branch to the repo. like:

git push -u origin b01 

Now I am done with the changes and want to merge it to the master branch. So I do a:

git checkout master 

Here is the error it throws:

fatal: cannot create directory at 'workfolder': Permission denied 

Git keeps me in b01, but deletes ALL the files I had created in the branch. So if I now do a

git status 

it shows me:

On branch b01 Your branch is upto date with 'orgin/b01' Changes not staged for commit: (use "git add/rm .....)   deleted: new file1   deleted: new file2 <list of the new files I had added but which got deleted as a result of the command> 

I am having to run a

git checkout -- .  

to restore the files.

Please help.

like image 404
TechiRik Avatar asked Sep 23 '16 00:09

TechiRik


People also ask

Can not create directory permission denied?

There are a couple of possible solutions to this issue: Create a folder that the user running the build has permissions to. Change the ownership of the directory with the chown command before trying to write to it.

Does git checkout change working directory?

Git Checkout File Checking out a file is similar to using git reset with a file path, except it updates the working directory instead of the stage. Unlike the commit-level version of this command, this does not move the HEAD reference, which means that you won't switch branches.


1 Answers

I had a similar situation. Though it was due to me having the solution open in visual studio. Closing visual studio and doing a git reset put me into a good spot.

I.e. check to see if any processes are locking the folder/files.

like image 101
gzimmers Avatar answered Oct 21 '22 09:10

gzimmers