21

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?

morpheus
  • 18,676
  • 24
  • 96
  • 159
  • See also http://stackoverflow.com/q/3829498/119790 – Ian Vaughan Jul 20 '11 at 11:04
  • Please see my answer at http://stackoverflow.com/questions/3829498/git-over-samba-unable-to-write-sha1-filename-permission-denied/6777323#6777323 – Ian Vaughan Jul 21 '11 at 14:11
  • @morpheus you need to mark an answer here. – jcollum Jan 15 '13 at 17:43
  • @jcollum - i could not fix my problem using answer by VonC. i never tried the answer by dulon. i am not debugging this issue any more. – morpheus Jan 15 '13 at 17:47
  • @morpheus yeah i've been in that situation before, I usually mark the one with the most upvotes as the answer – jcollum Jan 15 '13 at 18:02
  • 5
    @jcollum - there are pros and cons to it. When I see an answer marked as answer, I understand this has solved OP's question. Therefore, if I am unable to solve the problem with provided answer, I get really puzzled and nervous. So that is why I haven't marked it as answer. People upvote if answer is helpful - an upvote doesn't mean this answer solves the problem. – morpheus Jan 16 '13 at 19:56

9 Answers9

15

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

A_toaster
  • 1,196
  • 3
  • 22
  • 50
  • Thanks -- in addition to this I also had to chown andy:andy in the .git folder, I had changed some permission settings, but that error didn't come up until I ran this. – Andy Nov 26 '19 at 18:48
  • 1
    `git gc` on the bare repository site solved the problem for me, as well. – ngong Jan 06 '20 at 18:53
8

Even if it is about a different context (git+ssh), check the ACL associated with your repo.
See for instance this blog post.

As suggested in the SO question "Git pull error: unable to create temporary sha1 filename" (which has other interesting suggestions as well), try redoing your bare repo, this time with the config:

git config core.sharedRepository true
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

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.

Pipo
  • 4,653
  • 38
  • 47
1

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.

Kemin Zhou
  • 6,264
  • 2
  • 48
  • 56
0

I too get the same error but usually when doing a "git pull" using bash on windows machine.

For me, its related to some other application (usually a virus checker in my case) causing conflicts by holding onto the .git directory.

I can usually do "git pull" a few more times and it will eventually work (after failing with same permission denied error on a different hash value) or if I'm feeling in a hurry, I would stop my virus checker, do the git pull (which would work successfully first time without the permission error) and then very quickly switch the virus checker back on again.

dulon
  • 735
  • 8
  • 10
0

I had this same problem and was able to fix it by going to the C:\Program Files\Git then right click on git-bash.exe -> properties -> Compatibility -> Run this program as an Administrator.

Zepplock
  • 28,655
  • 4
  • 35
  • 50
0

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

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/17870811) – Jonathan Eustace Nov 07 '17 at 21:43
  • 1
    Great thanks for the tip. It was my first comment ever on this website, I will learn and improve. – Jamie Edwards Nov 08 '17 at 21:50
  • Edited and added some instructions as part of my answer. – Jamie Edwards Feb 20 '20 at 17:52
0

I had this issue during 2 days and i finally figured out a way to solve it. The error occurs because the branch (in the remote repository) you actually wanna push into is currently checked out. When applying the --mirror or --all option, at least a branch is checked out, therefore the permission denied.

So just switch to another branch on the remote and apply the push locally and this time it will work.

0

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.

dimir
  • 693
  • 6
  • 23