Git gc and git prune warnings when git fetch origin is run

14.2k views Asked by At

Working with remote repository at some moment I started recieving this when I run git fetch origin

Auto packing the repository in background for optimum performance.

See "git help gc" for manual housekeeping.

warning: The last gc run reported the following. Please correct the root cause and remove .git/gc.log.

Automatic cleanup will not be performed until the file is removed.

warning: There are too many unreachable loose objects; run 'git prune' to remove them.

This happens all the time. I found somewhere that git gc should help but it works only once (or seems to work) - after this and following git fetch origin I get

Auto packing the repository in background for optimum performance. See "git help gc" for manual housekeeping.

Later the situation repeats. I also tried to remove .git/gc.log - it doesn't help.

My git skills are really limited. Why do I get this warnings and how to fix the issue for long?

3

There are 3 answers

0
Eldar On

Updating Git to the latest version, worked for me to get rid of this error

2
torek On

This particular issue was due to a bug in Git (for which a fix was first applied in 2.20.0: see commit 3029970275b473dbf62149887a19a6b4879528d7, which has a good description of what's going on, but see also commit 095c741edd1d9604b6c285000a836721fd69f051, which has a contributory effect and was fixed in Git 2.17). If you had the buggy version of Git, it let too many loose objects accumulate over time.1 You can and should upgrade your Git version to one that won't let these objects accumulate so badly, but for now, just go ahead and run git prune manually when you're not doing anything else with the repository. Then run git gc manually when the prune finishes. You may need to run rm .git/gc.log as well.

(The problem will come back now and then until Git is upgraded.)


"Loose" objects are normal. Their opposites are "packed" objects, which are stored more efficiently. Normally git gc runs automatically now and then and notices when it's a good time to pack loose objects. Packing too often reduces efficiency; packing not-often-enough reduces efficiency; git gc is supposed to figure out the right time. But some Git versions had this broken for a while, leading to the problem you've observed.

It's not a big problem: it just means Git is being less efficient (slower to run) than it would be, if this hadn't been broken.

1
ShaileshAher On

This article helped me -

git fsck
git gc --prune=now
git prune  
git gc

And error should vanish.

Reference - https://medium.com/lynns-dev-blog/git-there-are-too-many-unreachable-loose-objects-c2df601b8001