RSSAmplifier

Hello there. on xrazis · Haris Razis · Apr 8, 2025

Cleansing my git repositories

0
Sign in to vote or save

Haris Razis · xrazis.com

 · 2 min · 270 words · gitdevops

Why should you cleanse your git repos?

Repositories can get bloated overtime. You end up carrying commits and history that you may no longer need. Or even worse, you may have commits that contain confidential data like secret keys.

Personally, I found that many of my repos were extremely large. For example, this blog was 391 MiB. That is an absurd size for a blog like this one, with simple styling and very few posts. The reason being? I used to commit images. Even after I switched to using a CDN, the problem was not alleviated as the images were still hiding in git history.

How to cleanse your repo

You can use git filter-branch to rewrite history, but despite the myriad of options, it is cumbersome, dangerous, and slow to use. I found two alternatives:

I choose the latter and decided to remove any blob larger than 32 kilobytes.

java -jar bfg.jar --strip-blobs-bigger-than 32k haris.razis.com.git

After that you have to reflog and run the garbage collector. du -sh showed me that the repo size was now 1.4 MiB. That is an improvement of almost 28,000% 🤯.

Why is my remote’s size the same?

Because the garbage collector was run locally. That also needs to be done on your remote. If you are selfhosting git, that is easy as you probably have a gc button in the admin panel. If you are using a provider like Codeberg or GitHub , you can ask them nicely to run it for you, or wait for garbage collector to run automatically .

Read the original on xrazis.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.