Git: Huge .git directory

If the size of .git directory of the repository grows faster than the repo itself, there might be binaries or tarballs inside.

There is a very usefull tool called bfg to remove those entries.

Usage example:

wget -o ~/bfg-1.14.0.jar https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar
alias bfg="java -jar ~/bfg-1.14.0.jar"
bfg --strip-blobs-bigger-than 1M .
git reflog expire --expire=now --all && git gc --prune=now --aggressive

Troubleshooting

Sometimes bfg complains about protected files that cannot be deleted. Using git rm and redoing commands from Usage example will do the job.