When common porcelain operations that create objects are run, they will check whether the repository has grown substantially since the last maintenance, and if so run git gc automatically. See gc.auto below for how to disable this behavior.
I used to do this, but once you garbage collect you can’t use git reflog and this option is too valuable vs saving disk space.
I use a similar snippet for Fish called gitamin because I view it as vitamins for git.
set -l git_dirs (fd -H --type d '.git' $_flag_d)
for git_dir in $git_dirs
set repo_path $git_dir/..
echo "--> Now optimizing $repo_path"
echo
git -C $repo_path gc --aggressive
echo
end
Alternative:
parallel --verbose git -C {} gc ::: ~/*/.git/.. ~/dev/*/.git/..
Pros compared to the linked script:
prune
, which does something else entirelyCons:
My script messes up submodules?
Sorry, fixed!
This also adds a dependency
It also drops two, Bash and GNU find.
This statement is false. From https://git-scm.com/docs/git-gc:
I used to do this, but once you garbage collect you can’t use git reflog and this option is too valuable vs saving disk space.
I use a similar snippet for Fish called
gitamin
because I view it as vitamins for git.