13

I want to view the total repo size of a project hosted on GitHub without having to clone it. Sometimes I do this:

  1. Start cloning some GitHub repository

    Receiving objects: 45% (218/476), 5.50 MiB | 27 KiB/s

    Already drained 5MB? Suspend...

    ^Z
    
  2. Clone the repository on a server with a normal internet connection just to see its size.

  3. Continue (or abort) the local cloning.

How do I find out the repository size in advance? In the search I see repository size, but not in other places.

12

Using Github API:

$ echo https://github.com/hlamer/enki.git | perl -ne 'print $1 if m!([^/]+/[^/]+?)(?:\.git)?$!' | xargs -i curl -s -k https://api.github.com/repos/'{}' | grep size
"size": 284,
  • On mac, there's no -i parameter for xargs, so it's: $ echo https://github.com/hlamer/enki.git | perl -ne 'print $1 if m!([^/]+/[^/]+?)(?:\.git)?$!' | xargs -I{} curl -s -k https://api.github.com/repos/'{}' | grep size – Daniel Golden Aug 11 '15 at 20:25
  • and that is size in... kilobytes? – capybaralet Apr 7 '16 at 3:50
7

In Firefox you can use the GitHub Repository Size add-on.

github info bar

  • Why the downvote? Does the extension or userscript fails to work or contains malware? – Vi0 Jan 13 '18 at 19:12
  • No, everything works just fine... – vstepaniuk Jan 13 '18 at 23:51
2

Use Google Chrome browser and install this extension

Adds the repo size to the home page:

GitHub Repo Size extension screenshot

0
curl \
-H "Accept: application/vnd.github.v3+json" \
-s https://api.github.com/repos/torvalds/linux | \
jq '.size' | \
numfmt --to=iec --from-unit=1024

Explanation:

  1. fetch repo info from github api using curl

We get a json response like this:

{
  "id": 2325298,
  "node_id": "MDEwOlJlcG9zaXRvcnkyMzI1Mjk4",
  "name": "linux",
  "full_name": "torvalds/linux",
  "private": false,
     ...
  "size": 3018913,  <<<This is what we need
  "stargazers_count": 99224,
  "watchers_count": 99224,
     ...
}

  1. Pipe the json response to jq parser and find the required attribute-value pair.

    . indicates the root of the json body and size is the required attribute from the root body

Output (the size in kB):

3018913
  1. Then pipe the output to numfmt
$ man numfmt

--to=[UNIT]
     iec    1K = 1024, 1M = 1048576, ...

--from-unit=N
     specify the input unit size (instead of the default 1)
     (it basically tells that the input is in kB(1024B) insted of B

Output:

2.9G

For private repos pass a token as a header

-H "Authorization: token GITHUB_TOKEN"

replace GITHUB_TOKEN with a github token that has access to private repos

https://command-not-found.com/jq

https://command-not-found.com/numfmt

  • 2
    Can you explain what this command does? How does it help in this situation? Thanks – codingbadger Oct 13 '20 at 6:48
  • It fetches repository metadata using curl, then extracts "size" field from it using jq, then converts raw bytes to human-readable filesize with numfmt. – Vi0 Oct 14 '20 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.