17

I'm looking for help !!

I am getting the following error message when trying to complete a git pull;

C:\Jenkins\Repo> git pull error: cannot open .git/FETCH_HEAD: Permission denied

The machine in question is Windows Server 2008 r2 OS and were using ssh to handle the authentication.

We have tried the following; Checked that the current user the correct read/write on the FETCH_HEAD file, which it does, also checking that the user has the correct permissions set on the repo root.

I have tried to load my private key (which I know 100% works and has permissions to the repo in question) and still the same issue... so from little I know regarding git I think this is more of a Windows issue

and lots of Google !

Any more ideas on what to do/check would be a great help !

craig Rickett
  • 428
  • 1
  • 5
  • 17
  • 5
    Do you *have* a `FETCH_HEAD` file? Can you delete it? (Running `fetch` will recreate it.) It's possible that another program has it open and `git` cannot recreate it. – Edward Thomson Sep 03 '15 at 16:09

8 Answers8

22

This happened to me after I upgraded to Windows 10. While my user is an administrator and Administrators had full access to the root repo folder, my user was not explicitly listed. I've added my user with Full Control and it solved the problem for me (had the same issue with Outlook refusing to read the PST file until I did the same thing).

So, for me, the solution is:

  • Right click on the folder, select properties
  • Security
  • Edit
  • Add
  • Type in my user name
  • Check Full Control under Allow
  • OK, OK
David Airapetyan
  • 5,301
  • 4
  • 40
  • 62
8

On Windows 10 this is what worked for me:

1. go to the repo folder 
2. right click on the .git folder and choose the last option - properties
3. on the general tab uncheck hidden checkbox if checked
4. hit apply and then ok

now go try git fetch or git pull and it should work.

Akash Yellappa
  • 2,126
  • 28
  • 21
  • 2
    Oh damn! I spent almost two days to check complex solutions (authentication changes, command line operations, etc.) about this issue whereas this **really simple** manipulation seems to solve it! – P. Mergey Feb 01 '20 at 17:45
  • I worked in my Downloads folder and figured I had to clear the Read-only attribute to be able to run git pull. A quick search online [showed](https://appuals.com/how-to-fix-folder-keeps-reverting-to-read-only-on-windows-10/) that Windows Virus & threat protection has a controlled folder access feature that keeps the folder as read-only. This is not even available for configuring when another antivirus such as a corporate-controlled one takes over. It seems the entire Downloads folder is controlled against writes by anything but the browsers. – eel ghEEz May 30 '22 at 14:18
3

This is fairly a common problem. I've come across it many times and almost all of the times, the issue is with the right permissions to the repo/directory .git/ and the right SSH keys to access the git repository.

You probably need to make the user, the owner of the repository chown (Give full access to the user) or, clone the repository to a different directory.

You can set the write permission with the following command go to your folder chown -R youruser:yourgroup .git/

Also try to un-hide the .git folder.

Anantha Raju C
  • 1,780
  • 12
  • 25
  • 35
  • Hey Anantha Raju C, thank you for getting back to me. This is on a Windows System so I have tried the Windows version of `chown -R` which is `takeown /R /D Y /F *` and that didnt take any effect. – craig Rickett Sep 03 '15 at 15:53
  • @craig Rickett this may help you to take ownership of the repo http://serverfault.com/a/27339/308384 – Anantha Raju C Sep 03 '15 at 16:17
2

In my case, this happend because I hide the .git folder by hand(usually it will be hide automatically) but I forgot it.

I have tried edit security but no effect. So I just show the .git folder and solve the problem.

May this can be help for someone

ysjiang
  • 623
  • 6
  • 11
2

This happened to me because after updating windows. Kindly try these steps:

  1. Right click on folder -> properties
  2. Under general there are two checkbox hidden and read only -> uncheck the hidden check box and click on apply
  3. Under security -> edit -> add user -> apply
  4. give full access to your user

This will work for you

0

just remove the folder,and clone again.

Chuancey
  • 1
  • 1
0

What I did was open powershell / command prompt with Administrative rights inside the repository, and I was able to pull / fetch / merge and push.

Joseph Wambura
  • 2,732
  • 2
  • 21
  • 24
0

This problem can also be caused by the caches Jenkins keeps of it's Git operations. I had tried chowning the files I thought were causing the problem, I also deleted the workspace completely.

After deleting %ProgramData%\Jenkins\.jenkins\workspaces\MY-BUILD* I still had the exact same error message.

In %ProgramData%\Jenkins\.jenkins\caches I deleted everything but you could probably just delete the git-<HEX_ID> and git-<HEX_ID>@tmp folders and retry the same checkout. This resolved the issue for me as Jenkins was forced to recreate the .git folder in both the workspace and the cache and the permissions were then correct.

Steps:

  1. Delete the workspace folders of the troublesome job
  2. Delete the Git caches
  3. Retry the job