Determining the size of the .git for a GitHub repo, without cloning it
Every so often, I'll be doing work that needs to know how big a Git repo is.
Right now, I'm doing some work in Renovate around how we support large repos and/or monorepos, and have hit the same question - "how big is that repo's .git folder", which gives an important guide for the minimum disk requirement needed for that repo.
(I thought I'd already blogged about this, but it seems like I hadn't)
A more convenient method is to use the GitHub API to look up that metadata, without needing to go through the pain of cloning it - even bloblessly - where we can instead:
gh api /repos/renovatebot/renovate --jq .size
172111
# ~168M
Per the docs:
The size of the repository, in kilobytes. Size is calculated hourly. When a repository is initially created, the size is 0.
We can see that if we clone the repo, we get a fairly similar number:
% git clone https://github.com/renovatebot/renovate
% du --summarize --apparent-size --human-readable renovate/.git
177M
# and with everything checked out
% du -sh renovate
211M
We can also compare this to a --bare clone:
% git clone https://github.com/renovatebot/renovate --bare renovate-bare
% du -sh renovate-bare
176M
There's a slight difference that may be due to GitHub's server-side configuration, but it's good enough to go off of.
Some other useful repos to check against, as they're ones I consider when thinking about "large repos I can access":
% gh api /repos/backstage/backstage --jq .size
8774031
# ~8568MB
# ~8.4GB
% gh api /repos/elastic/kibana --jq .size
19091449
# ~18643M
# ~18.2G