How to Fix an Oversized Git Repository Caused by Commit History

Apr 1, 2026 · 1 min read · 154 Words · -Views -Comments

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;
}'

https://static.1991421.cn/2026/04/2026-04-01-185743.jpeg

Solution

  1. git filter-repo –path xxx –invert-paths –force
  2. git push –force

Conclusion

  1. A large repo does not mean the current files are large.
  2. Large files may still exist in history, even if you have already deleted them.
Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover