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:

  • Git Source Control Provider hotkeys
  • Gitlab PUSH syntax error, unexpected ':', expecting $end
  • How does Git handle branches compared to SVN?
  • Error when “git push” to github
  • Exclude Files When Deploying from Git to Azure Websites
  • git branch: gh-pages
  • 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?

  • Git-flow reopening a finished feature
  • How to .gitignore files recursively
  • Git submodule init async
  • How to handle different instances of index.php in codeigniter with git
  • Failed to connect to github 443
  • How to make git-svn use specific version of SVN?
  • 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.