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 uncertainty - customized, but able to pull in upstream changes?
  • DAG vs. tree using Git?
  • Can I move the .git directory for a repo to it's parent directory?
  • Free GIT Server with Web GUI a la BitBucket/GitHub
  • Get size of removed lines
  • What is HEAD in 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?

  • git pull --rebase upstream & git push origin rejects non-fast-forward?
  • How to modify a snapshot (commit) in a linear history without conflict-related errors?
  • What's the difference between “Push…” and “Push to upstream…” in Eclipse
  • Is “git push --mirror” sufficient for backing up my repository?
  • Splitting a set of files within a git repo into their own repository, preserving relevant history
  • How to revert two commits back and commit only good stuff?
  • 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.