I recently needed to push an open-source project to the community, but the repository was reported as too large, several hundred MB. After downloading the current files, I found they were only about 10 MB, and there were only two branches. So I suspected the repository size problem came from Git history.
Install
brew install git-filter-repo
Find Which Paths Are Large
git rev-list --objects --all \
| git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize) %(rest)' \
| grep ' blob ' \
| sort -k3 -nr \
| head -20 \
| awk '{
size=$3;
path=$4;
for (i=5; i<=NF; i++) path=path " " $i;
if (size >= 1024*1024*1024)
printf "%.2f GB\t%s\n", size/1024/1024/1024, path;
else
printf "%.2f MB\t%s\n", size/1024/1024, path;
}'

Solution
- git filter-repo –path xxx –invert-paths –force
- git push –force
Conclusion
- A large repo does not mean the current files are large.
- Large files may still exist in history, even if you have already deleted them.

