Space Cat, Prince Among Thieves

git gc - You're not going to need it

I want to make a recommendation that every developer turn off automatic garbage collection in git. It's one of the first things I do setting up a new machine.

For a happier life, go to your terminal right now, and run:

$ git config --global gc.auto 0

You won't regret it.


Turn off garbage collection? Surely, I must be crazy, right? Automatic garbage collection is important, right, they wouldn't turn it on by default if it wasn't!? Not really.

Garbage collection for git in most every use case just isn't worth it. That is unless you're very regularly committing very large files, and then orphaning those commits. I don't see that happening in most uses cases; garbage just doesn't build up that quickly in normal usage.

Don't believe me?

I have been working with the same git repo every day for ten solid years with gc turned off. My .git folder is currently 554 MB whereas a fresh cloned copy is 112 MB. I could be saving a whole 442 MB - whoop de doo.

I don't know about you, but I'll happily pay 442 MB for 10 years of improved data safety.

But why turn it off?

Having it on means detached commits could disappear at any time. It's a lottery roll.

Turning off automatic gc means that anything you once committed will remain restorable, forever. Turning it off means if a rebase goes badly, you can always safely get back to the previous state of a now orphaned commit. There's zero chance of it ever disappearing.

Basically, turning automatic gc off means any amount of history rewriting is always undo-able.

Example

A simple call to git reflog will show you all recent commits, including ones that are no longer on any branch.

$ git reflog
98a9b6b HEAD@{1}: commit (amend): Increase footer font-size and line-height
edc192c HEAD@{2}: commit: Increase footer line height
0360c78 HEAD@{3}: commit: Update footer color to quiet lighthouse
9231f91 HEAD@{4}: commit: Burn down a bunch of old css
…

In the example above, commit edc192c became 98a9b6b when it was amended.

To undo that amend, I can reset the HEAD of my current branch back to edc192c. I have no fear of edc192c ever randomly disappear before I get around to it.


Turning off gc is a safety net that has saved me many times.

Turning off automatic gc means you could literally safely work on a detached HEAD if you're crazy. Probably don't do that unless you know exactly what you're doing.

And of course…

Keep in mind, you can always just run gc manually if you feel like a lot of garbage has piled up.

$ git gc

Read More / Comment »

Use a GIF as a Zoom Virtual Background

Update August 17 2021: I've got the tool working in Chrome and Firefox by launching it a standalone new window instead of loading in an iframe. It is still broken in Safari for unknown reasons. It's not ideal, but until the whole SharedArrayBuffer debacle settles down, it's probably the best I can …


Read More / Comment »

Recent Comments

Great tool, but I have one question - why the "\" character is inserted in the url? Below you can see example. This is what I pasted to first field (old-new …
Link

This is the one thing I never did until it was too late
Link

Very Helpfull
Link

Hi! Thanks a lot but how do I upload it? I've never done this before and I don't know how to upload it
Link

This is a drawing good link https://www.pixilart.com/draw?ref=home-page
Link