1 min read

Find large files in a git repository


When your repo clone takes forever

If your git clone is suspiciously slow, there are probably large files hiding in the history. Here’s how to find them.

List the 10 largest files currently tracked in the repo:

large_files_tracked.sh
git ls-files | xargs du -h | sort -rh | head -10

But that only shows the working tree. The real culprits are often buried in git history. Find the largest objects across all commits:

large_files_history.sh
git rev-list --objects --all \
  | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
  | sed -n 's/^blob //p' \
  | sort -rnk2 \
  | head -10 \
  | numfmt --field=2 --to=iec

This lists the 10 largest blobs ever committed, with human-readable sizes.

Once you’ve identified the offenders, consider using git filter-repo to remove them or set up a .gitattributes with Git LFS for future large files.