git checkout error: cannot create directory: Permission denied

TechiRik picture TechiRik · Sep 23, 2016 · Viewed 41.8k times · Source

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.

Answer

gzimmers picture gzimmers · Oct 2, 2017

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.