Get Github Repository size with BASH
Get Github Repository size with BASH
If you want to know the Github repo size before cloning it or for some other reason; you can use the Github REST API with jq and numfmt:
Bash command:
curl 'https://api.github.com/repos/git/git' | jq '.size' | numfmt --to=iec --from-unit=1024
- Replace
git\gitwith theuserand therepository_name
Explanation:
- We use the
curlcommand to get the json data from the API - The json data is passed to the jq module and then we get the
sizeproperty in which we are interested. - Then we use the numfmt to convert the size from integer to a human readable size.
numfmt --to=ieccommand converts the bytes in integer format to a human readable size. Based on the Github REST API documentation, thesizeis returned in Kbs. Knowing this we inform thenumfmtwith--from-unit=1024command that we are passing the integer in Kbs and not in bytes.
Got the numfmt command --from-unit=1024 here
Leave a comment