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.

55 questions
254
votes
10 answers

How to handle git gc fatal: bad object refs/remotes/origin/HEAD error?

I randomly hit this today while trying to run Git garbage collect: $ git gc fatal: bad object refs/remotes/origin/HEAD error: failed to run repack How do I deal with this?
Ryan
  • 3,325
  • 2
  • 17
  • 11
250
votes
12 answers

How do I remove the old history from a git repository?

I'm afraid I couldn't find anything quite like this particular scenario. I have a git repository with a lot of history: 500+ branches, 500+ tags, going back to mid-2007. It contains ~19,500 commits. We'd like to remove all of the history before Jan…
ebneter
  • 19,017
  • 9
  • 28
  • 30
247
votes
10 answers

How often should you use git-gc?

How often should you use git-gc? The manual page simply says: Users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance. Are there some commands to get…
readonly
  • 321,454
  • 105
  • 202
  • 204
138
votes
5 answers

How to skip "Loose Object" popup when running 'git gui'

When I run 'git gui' I get a popup that says This repository currently has approximately 1500 loose objects. It then suggests compressing the database. I've done this before, and it reduces the loose objects to about 250, but that doesn't…
Michael Donohue
  • 11,684
  • 5
  • 29
  • 44
64
votes
4 answers

How can I trigger garbage collection on a Git remote repository?

As we know, we can periodically run git gc to pack objects under .git/objects. In the case of a remote central Git repository (bare or not), though, after many pushes, there many files under myproj.git/objects; each commit seems to create a new file…
peterwang
  • 1,059
  • 2
  • 11
  • 10
44
votes
5 answers

Do I ever need to run git gc on a bare repo?

man git-gc doesn't have an obvious answer in it, and I haven't had any luck with Google either (although I might have just been using the wrong search terms). I understand that you should occasionally run git gc on a local repository to prune…
Mark Rushakoff
  • 235,438
  • 44
  • 396
  • 394
41
votes
5 answers

Is there a way to limit the amount of memory that "git gc" uses?

I'm hosting a git repo on a shared host. My repo necessarily has a couple of very large files in it, and every time I try to run "git gc" on the repo now, my process gets killed by the shared hosting provider for using too much memory. Is there a…
sam2themax
  • 998
  • 2
  • 9
  • 14
37
votes
5 answers

Git gc using excessive memory, unable to complete

Final update and fix: The solution here turned out to be a combination of two things: using Windows Git rather than Cygwin Git as Graham Borland suggested, and the Git config settings pack.threads = 1 and gc.aggressiveWindow = 150. I have a large…
me_and
  • 14,344
  • 6
  • 61
  • 96
34
votes
3 answers

Stopping a git gc --aggressive, is that a bad thing?

I am running a git gc --aggressive on a very large repo (apx 100 gb). It's been running since two nights ago, and as of a couple hours, it has been stuck on: "Compressing Objects: 99% (76496/76777)" If I Ctrl-C the process, what are the…
imyjimmy
  • 651
  • 1
  • 9
  • 17
26
votes
1 answer

What do the numbers in the "Total" line of git gc/git repack output mean?

When I run git gc or git repack over my Git repository, it outputs a "Total" line once it's done. What do these numbers mean? A couple of examples from a fairly small repository: $ git gc ... Total 576 (delta 315), reused 576 (delta 315) $ git…
me_and
  • 14,344
  • 6
  • 61
  • 96
25
votes
2 answers

How to REALLY delete a git branch (i.e. remove all of its objects/commits)?

I have a git tree like A---B---C topic / D---E---F---G master <-- I would like to remove topic and all objects on it. I note the SHA ID of topic, then type: git branch -D topic git gc …
Alan
  • 291
  • 3
  • 3
17
votes
2 answers

List of all commands that cause git gc --auto

Is there a definitive list of commands anywhere that cause git gc --auto to run? The git-gc(1) man page simply states: --auto With this option, git gc checks whether any housekeeping is required; if not, it exits without performing any work. Some…
rejj
  • 1,206
  • 6
  • 13
14
votes
1 answer

When exactly does git prune objects: why is "git gc" not removing commits?

I'm working on a git course and wanted to mention that lost refs are not really lost until running git gc. But verifying this, I found out that this is not the case. Even after running git gc --prune=all --aggressive the lost refs are still…
exhuma
  • 17,395
  • 9
  • 83
  • 114
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,722
  • 1
  • 19
  • 43
11
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
  • 14,603
  • 17
  • 58
  • 92
1
2 3 4