RetroFed Forum
Your home away from modern life.
How can the size of a repo be determined /before/ cloning it?
Post Reply
AuthorMessage
freedomPusher sopuli.xyz freedomPusher@sopuli.xyz
Joined: 2021-03-06
Quote

The git clone command assumes everyone has unlimited fixed-rate Internet. I have no Internet.
Sometimes I’m on a friend’s measured rate uplink with a tight quota. So I cannot be blindly fetching a repository that blows copious amounts of quota.

Fuck surprises. They suck. How do I inform myself of the consequences of git clone before running it?

HTTP has a useful facility: the content-length: header. So this gives a way to get the size of a single web object before fetching:

curl -L --head "$url" | grep -i content-length

If git count-objects were sophisticated enough, it could perhaps theoretically get a tree of objects without their contents and perform the above header check on each object.

The only viable option is apparently to run git clone in a remote shell account just for the purpose of running git count-objects, then delete the clone and rerun the clone op locally if the size is acceptible.

Any better ideas?

1   Original
SnoopSqueak lemmy.today SnoopSqueak@lemmy.today
Joined: 2026-07-09
#2 · Quote Reply

Instead of git clone, initialize a new local repository, add the remote origin, and then git fetch:

https://stackoverflow.com/questions/2882620/is-it-possible-to-remote-count-object-and-size-of-git-repository

3
freedomPusher Moderator freedomPusher@sopuli.xyz
Joined: 2021-03-06
#3 · (edited) Quote Reply

Instead of git clone, initialize a new local repository, add the remote origin, and then git fetch: https://stackoverflow.com/questions/2882620/is-it-possible-to-remote-count-object-and-size-of-git-repository

Thanks! That link is jailed in Cloudflare’s walled garden but this variant is reachable to everyone (in case someone else wants to follow this):

https://overflow.ocus.top/questions/2882620/is-it-possible-to-remote-count-object-and-size-of-git-repository

The fetch operation does not disclose the total before fetching, but it gives a way to monitor progress which is good enough in some situations. I wonder if the percentage can be trusted. If the percentage is accurate, then it must also know the total. But the ratio is not apparently based on size.

Further down in your same article, there is a Github-specific way to get the size, which I tweaked to:

$ curl -sL https://api.github.com/repos/Marijnh/CodeMirror | jq -r .size

Perhaps the best generic answer (independent of Github) is further down the same page. This comment gives a codified way of doing what I was contemplating.

I appreciate the helpful link. Though I’m seeing a huge discrepency. E.g., for this repo, curl gives 34785 (which is apparently in kilobytes) and git count-objects -vH after fetching gives about the same answer. Yet the repo is actually nearly double that size (~61 mb).

2
Post Reply
Back to top