How to remove unreferenced blobs from my Git repository

I present to you this useful command, “git-gc-all”, guaranteed to remove all your Git garbage until they might come up extra configuration variables:

git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 \
    -c gc.rerereunresolved=0 -c gc.pruneExpire=now gc

You might also need to run something like these first:

git remote rm origin
rm -rf .git/refs/original/ .git/refs/remotes/ .git/*_HEAD .git/logs/
git for-each-ref --format="%(refname)" refs/original/ |
    xargs -n1 --no-run-if-empty git update-ref -d

You might also need to remove some tags:

git tag | xargs git tag -d

Leave a Comment