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

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:

  • My pull request has been merged, what to do next?
  • Copy file and its entire history
  • Is it possible to have git encrypt and decrypt a file during a push/pull?
  • Dockerfile strategies for Git
  • Git and cloning
  • Setting up Xamarin Studio Version Control with TFS + git
  • 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?

  • Weird git merge result
  • Understanding GPL better
  • What is the difference between git checkout commit-name and git checkout branchname
  • Phpstorm creating random diffs that I did not make
  • What's the equivalent in Git to a read-only component in ClearCase?
  • In a GitHub commits response, what is the difference between an author and committer?
  • 3 Solutions collect form web for “git error “unable to write sha1 filename … Permission denied””

    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

    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.

    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.

    Git Baby is a git and github fan, let's start git clone.