brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git count-objects -vH shows how big your repository really is

Git
~/tips/tip-git-count-objects-repo-size

git count-objects -vH

Reports how much disk space the repository's objects take, in readable units.

A clone that takes forever, a .git folder bigger than the project: before I go looking for big files, I want to know how big the repository actually is.

git count-objects -vH

-v gives the full report and -H prints sizes in KiB, MiB and GiB instead of raw numbers:

count: 73
size: 292.00 KiB
in-pack: 15230
packs: 2
size-pack: 148.31 MiB
garbage: 0

count and size are loose objects, ones git hasn’t packed yet. in-pack and size-pack are the compressed packfiles that hold most of the history. size-pack is the number that comes closest to what a full clone downloads.

A lot of loose objects is normal after a busy day and git packs them during its automatic maintenance. If garbage isn’t zero, something odd is lying in the objects folder that git couldn’t use.

This tells you how big, not why. To find the files that make a repository heavy, list blobs by size with git rev-list --objects --all together with git cat-file --batch-check. And keep in mind that a deleted big file still counts here, because it lives on in history until you rewrite it out.

Further reading: git-count-objects documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link