Reputation: 52817
Is there an easy way to get the size of a public or private github repository?
I tried this method which seems to work well for public repositories (returning "size": 2994520
):
echo https://github.com/torvalds/linux.git | perl -ne 'print $1 if m!([^/]+/[^/]+?)(?:\.git)?$!' | xargs -I{} curl -s -k https://api.github.com/repos/'{}' | grep size
but doesn't seem to work for private repositories (it returns the message 'Not Found')
Is there some way (via an API, the browser, or bash script) that can retrieve the size of a github repository (as distinct from a local git repository)?
Note: important that the solution works for private repositories the user has access to (not just public ones)
Upvotes: 1
Views: 712
Reputation: 171
You need to pass a PAT(Personal Access Token) to curl. this authenticates you as a user with github, which in turn lets you access your private repos.
You can create a PAT by following instructions here Creating a Personal Access Token
Then run
echo https://github.com/torvalds/linux.git | perl -ne 'print $1 if m!([^/]+/[^/]+?)(?:\.git)?$!' | xargs -I{} curl -s -k -u <username> https://api.github.com/repos/'{}' | grep size
and when asked for, provide the token you created earlier. Be sure to replace your username in the command
you can also directly pass in the token in the command
echo https://github.com/torvalds/linux.git | perl -ne 'print $1 if m!([^/]+/[^/]+?)(?:\.git)?$!' | xargs -I{} curl -s -k -u <username>:<token> https://api.github.com/repos/'{}' | grep size
Upvotes: 1