Optimize your .git
— Kaushal ModiI 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 searching online 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'