git gc error: failed to run repack

I’ve just run git gc on my local repository to do some regular clean-up. Today for the first time, it failed. Here’s what I’ve done: (Windows 7)

C:\Source\TxTranslation>git gc
Counting objects: 880, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (540/540), done.
Writing objects: 100% (880/880), done.
Total 880 (delta 504), reused 589 (delta 333)
rm: cannot unlink `pack-18179305b5b5dbdaf059e4ded50b736ab93e220c.pack': Permission denied

C:\Source\TxTranslation>git gc
Counting objects: 880, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (369/369), done.
Writing objects: 100% (880/880), done.
Total 880 (delta 504), reused 880 (delta 504)
mv: cannot move `/c/Source/TxTranslation/.git/objects/pack/pack-3002d22690e007a4205f6ecfa19d6e93296fdd78.pack' to `/c/Source/TxTranslation/.git/objects/pack/old-pack-3002d22690e007a4205f6ecfa19d6e93296fdd78.pack'
error: failed to run repack

I can retry it as often as I want, I always get the second output again. The “premission denied” error above is nonsense. I believe it’s a common spurious error that I see on many Windows systems these days. It may be coming from virus scanners that keep files open so that they can’t be deleted immediately. That leads to all sorts of issues but apparently can’t be avoided.

  • Safe to run git gc
  • Remove mysterious ref from Git
  • Git: automatic clean-up?
  • How to skip “Loose Object” popup when running 'git gui'
  • How to force garbage collection on a remote bitbucket repository
  • Git: how to repack all loose commits
  • Is this a problem? Is something broken? I absolutely don’t understand what those message mean to me. Browsing the log with diffs still works. What could I do to fix that problem? (Luckily I have pushed everything to Github just before, so I could simply re-clone it, but I’d like to try fixing it first, in case it happens again.)

  • Merge Request approvals in GitLab CE
  • How to create releases in GitLab?
  • What is the point of 'git submodule init'?
  • target directory empty after git push to remote
  • Git SVN case sensitive folder names
  • Jenkins - Can't push tag to remote repository
  • 6 Solutions collect form web for “git gc error: failed to run repack”

    As it turned out, Visual Studio had a lock on some of Git’s files. Closing Visual Studio resolved the issue.

    FTR, I’m using the Git source control provider (in the last usable version 0.6.4) in VS2010. Maybe this is part of the cause.

    I got the same issue using eclipse . The was accessing git repository through Eclipse as well as git bash.

    Solved by running the gc after closing eclipse

    Environment

    Windows 7

    Git 1.8.4.mysysgit.0

    Eclipse Kepler SR2

    Hope this helps others.

    In my case I found that Tortoise Git process was the culprit for locking files.
    Terminating the process allowed me to git gc

    In my case a running IISExpress instance was to blame.

    If you were doing some other operation with git, or some git-related operation in a GUI, cancel the operation or close the error, and manually run a git gc, then try your operation again. Basically, on windows, this message is an indication of contention between the git command line client and some other program.

    In my case, the repack had been triggered automatically as part of a git pull. When I got the error, after ruling out a permission issue with a quick sanity check that none of the things that would be launching git processes (IDE, git bash, git GUI) would be running elevated, I went to Process Explorer to find out what process had the file open (Find -> File Handle or DLL), and it found a git.exe that was a parent of the other git.exe process. I’m guessing that there are some locking assumptions in the automatic repack code that aren’t appropriate in a Windows port, where by default opening a file puts an exclusive read/write lock on the file at the OS level.

    That was with

    $ git --version
    git version 1.9.2.msysgit.0
    

    This happened to me even AFTER I closed my solution in Visual Studio, but was resolved when I finally closed VS. I was NOT using the git source control extension.

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