Questions tagged [git-gc]

The `git gc` function is used to perform housekeeping in a Git repository, run automatically by certain other Git operations, or manually.

General information

This function performs a number of housekeeping operations on a Git repository, including compressing file revisions and removing unreachable objects.

There are three main modes of operation:

  • Automatic. Certain Git commands will run git gc --auto, which will attempt to determine whether clean-up is necessary, and perform it if so. Automatic housekeeping can be disabled by running git config gc.auto 0.

  • Manual. You can run git gc from the command line whenever you like. This is particularly important if you've disabled the automatic operation as above.

  • Aggressive. Running git gc --aggressive will perform a much slower and more thorough optimization. The Git man pages recommend doing this only "every few hundred changesets or so", since the effects are persistent.

See also the Git man page for git gc.

On Stack Overflow

The "git-gc" tag should be used for anything to do with this command: when to run it, how to run it, how to resolve problems with running it or caused by running it, and how to configure how it works.

61 questions
14
votes
1 answer

Git Repository Too Large

I have a project with ~12MB worth of code and assets in it. I've been tracking it using Git, and just noticed that my .git folder is now just over 1.83GB. It consists of a few small files, and then just one pack file that makes up about 1.82GB of…
Bryce
  • 2,802
  • 1
  • 21
  • 46
13
votes
1 answer

Git: When does Git perform garbage collection?

I was wondering: when does Git perform its garbage collection? I know that in the past one had to invoke git gc to manually start the garbage collection, but now it is done automatically, when? Also, is there a need to invoke it manually in the…
Wazery
  • 15,394
  • 19
  • 63
  • 95
10
votes
3 answers

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

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…
Dmitriy Metelya
  • 109
  • 1
  • 1
  • 4
10
votes
3 answers

Forcing Remote Repo to Compress (GC) with Git

I'm using Git to version a series of binary files. They compress pretty well, but my central repos do not seem to be compressing when I push to them. They're eating up a decent amount of my quota, so I was looking to see if there was a way to force…
jocull
  • 20,008
  • 22
  • 105
  • 149
9
votes
2 answers

Trying to redirect 'git gc' output

I have a @daily job in the crontab that runs git gc on all the repos. I'm trying to set up a log file for the job but I/O redirection does not produce the results I am looking for; I get a blank file. I've done all the usual >, 2>&1 and so on…
s k
  • 103
  • 5
8
votes
2 answers

git gc and git pull locks up machine and never finishes

When running git gc, git gets up to 99% complete and then locks up. I let it run all night and it never finished, and did not seem to progress. Generally I have to hard-reset the machine to recover because everything locks up. Because the machine…
Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
7
votes
1 answer

Are "dangling" and "loose" objects the same?

Git's fsck doc talks about "dangling" objects, while the gc doc talks only about "loose objects". There's a strict split. But while skimming a few related SO posts, the terms seem to be used interchangeably. In the Git Book v2 and Git's source code…
Katrin Leinweber
  • 1,316
  • 13
  • 33
7
votes
3 answers

Is there any difference between `git gc` and `git repack -ad; git prune`?

Is there any difference between git gc and git repack -ad; git prune? If yes, what additional steps will be done by git gc (or vice versa)? Which one is better to use in regard to space optimization or safety?
7
votes
2 answers

Git: automatic clean-up?

In the past, one had to invoke git gc from time to time. I've read now, that latest Git versions should perform the cleanup automatically. Is this correct?
Mot
  • 28,248
  • 23
  • 84
  • 121
6
votes
1 answer

Failed to run repack in git gc

Tried below command and facing error. > git gc Counting objects: 6342699, done. warning: suboptimal pack - out of memory fatal: Out of memory, malloc failed (tried to allocate 239971384 bytes) error: failed to run repack I have tried git config…
Selva
  • 179
  • 1
  • 3
  • 13
6
votes
3 answers

git gc on machine with quota

Simple question, I'm trying to run git gc on a machine with a quota. Pre-gc, I'm at about 18GB of usage, almost all of which is my cloned git repository. My disk limit is 25GB. During the git gc operation, enough temporary files are written to disk…
Cory Petosky
  • 12,458
  • 3
  • 39
  • 44
5
votes
1 answer

After a git reset, unreachable commit not removed

I have a small repo that has a couple of commits: * a0fc4f8 (HEAD -> testbranch) added file.txt * e6e6a8b (master) hello world now * f308f53 Made it echo * f705657 Added hello * 08a2de3 (tag: initial) initial Also: $ git status On…
Jim
  • 18,826
  • 34
  • 135
  • 254
4
votes
1 answer

Number of threads for git gc depending on repo size

Can I use single-threaded compression in Git for large repositories and usual parallelized one for small ones? Like "pack.threads=1" if don't easily fit in momory and "pack.threads=4" otherwise. As I heart somewhere, multithreaded "git gc" requires…
Vi.
  • 37,014
  • 18
  • 93
  • 148
4
votes
1 answer

Determine what prevents a commit from being pruned from git

How can I determine what is preventing a commit from being pruned from git by the following commands? git reflog expire --expire=now --all git gc --prune=now Details I want to completely remove a commit (with, e.g., commit hash XYZ) from my clone.…
XDR
  • 4,070
  • 3
  • 30
  • 54
4
votes
1 answer

Why git operations becomes slow when repo gets bigger

I know git would get slow when the repo get bigger. But why? As git stores files as separate directories and files under .git, i can not find out why the operations get slowwer. Let's have a look at the commit operation. Recently, i cloned the…
Mr. C
  • 548
  • 5
  • 17