git error “unable to write sha1 filename … Permission denied”

Viewed 45085

I am using git on windows. This is what I did: doing development on machine M1, created bare repository on USB drive M2 to backup the repository on M1. I did backups using this command (from git bash on M1):

git push --mirror "f:\repo"

Worked without any issues. Then I bought a new machine M3. I cloned the repository from M2 to M3:

git clone "f:\repo" .

Made some checkins to the repo in M3. Then I did (from git bash on machine M3)

git push --mirror "f:\repo"  

I get this error: unable to write sha1 filename … Permission denied How can I fix this?

9 Answers

Bit late but none of these worked for me. I had to run sudo git gc in the remote repository and that somehow fixed all my problems.

After that I pushed again and it worked

Ran into this error because of permissions on distant respository. In my case it was the ssh user which was the wrong one for rights.

My particular error messages:

error: unable to write sha1 filename ./objects/ee/7ed0ef8db273d8d0acef46f3cc8ad0ae140d50: Permission denied

I just fixed my problem. It turned out to be the repository issue. In the /GIT/HOME/projectdir/objects/

doing ls you should see a lots of directories with 2 letters:

00  0a  14  1e  28  32  3c  46  50  5a  64  6e  78  82  8c  96  a0  aa  b4  be  c8  d2  dc  e6  f0  fa
01  0b  15  1f  29  33  3d  47  51  5b  65  6f  79  83  8d  97  a1  ab  b5  bf  c9  d3  dd  e7  f1  fb
02  0c  16  20  2a  34  3e  48  52  5c  66  70  7a  84  8e  98  a2  ac  b6  c0  ca  d4  de  e8  f2  fc
03  0d  17  21  2b  35  3f  49  53  5d  67  71  7b  85  8f  99  a3  ad  b7  c1  cb  d5  df  e9  f3  fd
04  0e  18  22  2c  36  40  4a  54  5e  68  72  7c  86  90  9a  a4  ae  b8  ... (many others removed) info pack

Here I just list a few for example (ee that trigger the error message is one of them). ls -l will show some directories got -r read only permission. using the git account do chmod -R +w on those directories missing the w label solved my problem. In my case several directories including 'ee' missed the write permission.

We ran into this issue when a colleague did not have the correct umask setting in his .bashrc that caused any files he committed to be set as read only for the rest of us trying to write changes to that same file in the git repo.

You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux distro set it to 0022 (022) or 0002 (002). Open /etc/profile or ~/.bashrc file, enter:

# vi /etc/profile

OR

$ vi ~/.bashrc

Append/modify following line to setup a new umask:

umask 022

Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file (C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user’s environment at login).

Here is a link explaining umask permissions

This can also happen when your remote resides on the same machine and is owned by root, e. g.

$ git remote -v
origin  /root/git/project.git (fetch)
origin  /root/git/project.git (push)

In this case you either need to push as root or adjust the permissions of remote to allow different users to push.

Related