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
334
votes
17 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
  • 4,425
  • 2
  • 23
  • 12
287
votes
13 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
  • 20,795
  • 9
  • 30
  • 30
259
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
  • 343,444
  • 107
  • 203
  • 205
146
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,776
  • 5
  • 31
  • 44
69
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,159
  • 2
  • 11
  • 11
47
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
  • 1,068
  • 3
  • 10
  • 14
45
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
  • 249,864
  • 45
  • 407
  • 398
38
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
  • 15,158
  • 7
  • 59
  • 96
38
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
  • 711
  • 2
  • 11
  • 18
31
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
  • 15,158
  • 7
  • 59
  • 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
18
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,216
  • 7
  • 13
18
votes
1 answer

What are the dos and don'ts of custom objects and refs?

Let's say I want to write a small helper that allows to append some metadata to a repository in a way that can propagate to clones via refs. Simple example (a git-notes clone prototype that doesn't even attach the notes to any other git…
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
17
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
  • 20,071
  • 12
  • 90
  • 123
14
votes
2 answers

What does git do when we do : git gc - git prune

What's going on in background when launching, git gc git prune Output of git gc : Counting objects: 945490, done. Delta compression using up to 4 threads. Compressing objects: 100% (334718/334718), done. Writing objects: 100% …
L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57
1
2 3 4 5