Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git repository size is larger than it should be

Tags:

git

So I'm using git on a personal server and I had an old repo that I needed to update. I removed a bunch of old files and committed and pushed the change. I'm using a web UI for it on my server (Gitlist). When I use this GUI to download the repo as a zip file, it comes out to the correct size, about 41MB. However, when I clone the repo, it comes out to something closer to a gig due to the size of one of the ./git/objects/pack files is about 900MB.

Why is the repo so large when it really should be much smaller?

like image 884
Febble Avatar asked Jul 02 '14 19:07

Febble


People also ask

Why is my Git repo so big?

But, even in that case, you keep on committing large files, your git repo size may increase due to the version history. You have to reduce your git repo size in order to work it seamlessly. Ideally, we should keep your repository size to between 100MB and 300MB.

How big should Git repos be?

We recommend repositories remain small, ideally less than 1 GB, and less than 5 GB is strongly recommended. Smaller repositories are faster to clone and easier to work with and maintain.


1 Answers

Pushing a commit which removes files doesn't lake the git repo smaller.

You need to remove those files across the history of the git repo in order for it size to shrink.
This is typically done with a combination of git filter-branch and git gc --aggressive --prune=now: see "Reduce git repository size".
(Don't forget: a git gc alone can actually increase the size of the repo!)

To remove large files, the tool BFG can help too.

In short, don't mix-up:

  • a zip image (representing one revision of a repo)
  • the full repo (representing all commits)

The HEAD that you download as a zip is indeed smaller (you removed files).
But the full history still references them.

like image 82
VonC Avatar answered Nov 06 '22 05:11

VonC