Emacs, scripting and anything text oriented.

Optimize your .git

Kaushal Modi

I was reviewing what was occupying the maximum disk space using the ncdu command line utility. One of the top candidates was the git clone of org-mode. It was using 2.4GB of my disk space!

Surprised by that, I started looking around1 if there was a way to optimize the cloned git repositories i.e. the .git/ directories. And sure enough, there was a way.

From this SO solution, all I needed to do was run the below in the git repo directory.

git reflog expire --all --expire=now
git gc --prune=now --aggressive

After running the above, the org-mode git repo shrunk down to 68MB!


I will find myself needing this for various git projects. So I created an alias called git_optimize for my tcsh shell.

alias git_optimize 'git reflog expire --all --expire=now; \\
                    git gc --prune=now --aggressive'

  1. I mean, started googling :) [return]

If you have written a response to this, enter your response post's URL below.

Or, you can send a "comment" webmention (it's OK if you don't know what that means). When asked about your website on an IndieAuth login screen, simply type https://commentpara.de.

Markdown Support**bold**, _italics_, ~~strikethrough~~, [descr](link), `monospace`, ```LANG\nline1\nline2\n``` (Yep, multi-line code blocks too, with syntax highlighting!), auto-hyperlinking.

Webmentions #

Comment by NoonianAtall on Fri Sep 1, 2017 23:44 EDT

You could also specify that as a global git alias, then you could call it like "git optimize" from anywhere. :)

Just be careful with the expiring and pruning. Once in a while the reflog saves me from a mistake. A few dangling commits usually won't make a significant difference in disk usage.

By the way, the CSS you're using makes all body text 25% larger than the user's browser setting, and the story titles are 2.5 times normal size, so everything's REALLY REALLY BIG. I used the browser inspector to turn off those rules and restore normal font sizes, and it's much easier to read. :)

Comment by Kaushal Modi on Sat Sep 2, 2017 09:33 EDT
Replying to comment by NoonianAtall: "You could also specify that as a …"

Thanks for the git alias tip.. I'll have a look. I do not have a single git alias at the moment as I don't use git at work (only for OSS projects). As I learned git through Magit, I never got to the git alias hacking :)

Thanks for mentioning the big font sizes.. you are not the first one to say so. I believe the fonts look a bit better now. Let me know. I don't code CSS professionally.. so I been constantly hacking at it.. I fix one thing but breaks another :P

Here is the commit attempted at this font size improvement. I still cannot make it go down to 100%.. need to fully understand the fancy underline shadows..