Search code examples
gitbitbucket

How to cleanup garbage in remote git repo


I recently ran into a size limit with my Bitbucket repo. I followed the countless other questions answering how to clean up your git repo and ended up using BFG to remove some bad commits.

This worked great, however, I noticed that after running a git count, there was a large amount of space sitting in garbage. So I ran a simple git gc. However, that did nothing to clean up the garbage.

After some digging I found the following command:

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

Running this led to the garbage being cleaned up locally. However, I still have the issue of the remote repo. Do I now need to get Bitbucket to run this command on my remote repo, or is there a way to push this change to the repository?


Solution

  • If anyone else is experiencing this, the answer turned out to be yes.

    Bitbucket support ran the following:

    git reflog expire --expire="1 hour" --all
    git reflog expire --expire-unreachable="1 hour" --all
    git prune --expire="1 hour" -v
    git gc --aggressive --prune="1 hour"
    

    The before and after reduced the remote repo size from over 2GB, to under 1GB.