17

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.

1

6 Answers 6

13

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,
2
  • 2
    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 Commented Aug 11, 2015 at 20:25
  • 1
    and that is size in... kilobytes? Commented Apr 7, 2016 at 3:50
7

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

github info bar

3
  • Why the downvote? Does the extension or userscript fails to work or contains malware?
    – Vi0
    Commented Jan 13, 2018 at 19:12
  • No, everything works just fine...
    – vstepaniuk
    Commented Jan 13, 2018 at 23:51
  • also it's opensource, so you can review the code yourself.
    – vstepaniuk
    Commented Nov 20, 2022 at 6:18
3

One can achieve this using one's browser console and running

fetch('https://api.github.com/repos/[USERNAME]/[REPO]')
  .then(v => v.json()).then((function(v){
   console.log(v['size'] + "KB")
  })
)

Let's consider a practical example.

Assuming one wants to find the size of this repo using Firefox.

Open the console with Ctrl+Shift+K.

Then paste the following code

fetch('https://api.github.com/repos/goncaloperes/TimeSeries')
  .then(v => v.json()).then((function(v){
   console.log(v['size'] + "KB")
  })
)

Press enter and one will receive the size of the repo as one can see in the image bellow.

enter image description here

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
  • 2
    Can you explain what this command does? How does it help in this situation? Thanks Commented Oct 13, 2020 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
    Commented Oct 14, 2020 at 21:59
0

For Mac users

The following one-liner should do the trick:

echo https://github.com/andreikop/enki.git | perl -ne 'print $1 if m!([^/]+/[^/]+?)(?:\.git)?$!' | xargs -I{} curl -s -k https://api.github.com/repos/'{}' | grep size
# "size": 17039

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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