Is there a way to see how big a Git repository is on GitHub before you decide to clone it?
This seems like a really obvious/basic statistic, but I can't find how to see it on GitHub at all.
Is there a way to see how big a Git repository is on GitHub before you decide to clone it?
This seems like a really obvious/basic statistic, but I can't find how to see it on GitHub at all.
There's a way to access this information through the GitHub API.
GET /repos/:user/:repo
When retrieving information about a repository, a property named size
is valued with the size of the whole repository (including all of its history), in kilobytes.
For instance, the Git repository weights around 124 MB. The size
property of the returned JSON payload is valued to 124283
.
The size is indeed expressed in kilobytes based on the disk usage of the server-side bare repository. However, in order to avoid wasting too much space with repositories with a large network, GitHub relies on Git Alternates. In this configuration, calculating the disk usage against the bare repository doesn't account for the shared object store and thus returns an "incomplete" value through the API call.
This information has been given by GitHub support.
If you own the repository, you can find the exact size by opening your Account Settings → Repositories (https://github.com/settings/repositories), and the repository size is displayed next to its designation.
If you do not own the repository, you can fork it and then check the in the same place.
Note: You might be the owner of the organization that hosts multiple repositories and yet not have a role in a specific repository inside the organization. By default, even if you create a repository in the organization you own, you are not added to the repo and hence not see that repo in settings/repositories
. So add yourself in the repository Setting(https://github.com/org-name/repo-name/settings
) to see it in https://github.com/settings/repositories
Somewhat hacky: use the download as a zip file
option, read the file size indicated and then cancel it.
I do not remember if downloading as a zip ever worked, but in any case, doing so now only downloads the currently selected branch with no history.
If you use Google Chrome browser you can install the GitHub Repository Size extension.
Repo here: https://github.com/harshjv/github-repo-size
@larowlan great sample code. With the new GitHub API V3, the curl statement needs to be updated. Also, the login is no longer required:
curl https://api.github.com/repos/$2/$3 2> /dev/null | grep size | tr -dc '[:digit:]'
For example:
curl https://api.github.com/repos/dotnet/roslyn 2> /dev/null | grep size | tr -dc '[:digit:]'
returns 931668
(in KB), which is almost a GB.
To do this with curl (sudo apt-get curl) and json pretty (sudo gem install jsonpretty json):
curl -u "YOURGITHUBUSERNAME" http://github.com/api/v2/json/repos/show/OWNER/REPOSITORY |
jsonpretty
Replace YOURGITHUBUSERNAME with your GitHub username (go figure).
Replace OWNER with the repository owner's Git username. Replace REPOSITORY with the repository name.
Or as a nice Bash script (paste this in a file named gitrepo-info):
#!/bin/bash
if [ $# -ne 3 ]
then
echo "Usage: gitrepo-info <username> <owner> <repo>"
exit 65
fi
curl -u "$1" http://github.com/api/v2/json/repos/show/$2/$3|jsonpretty
Use it like so:
gitrepo-info larowlan pisi reel
This will give me information on the pisi/reel repository on GitHub.
You need to follow the GitHub API. See the documentation here for all the details regarding your repository. It requires you to make a GET request as:
GET /repos/:owner/:repository
You need to replace two things:
E.g., my username maheshmnj, and I own a repository, flutter-ui-nice, so my GET URL will be:
https://api.github.com/repos/maheshmnj/flutter-ui-nice
On making a GET request, you will be flooded with some JSON data and probably on line number 78 you should see a key named size that will return the size of the repository.
Tip: When working with JSON I suggest you to add a plugin that formats the JSON data to make reading JSON easy. Install the plugin.
For a private repository, you will need to obtain a Personal Access Token from https://github.com/settings/tokens.
Then use the following curl command to get the details (substituting in values for [token], [owner] and [name]):
curl -u git:[token] https://api.github.com/repos/[owner]/[name] 2> /dev/null | grep size
As mentioned earlier, size may be in MB or KB.
To summarize @larowlan, @VMTrooper, and @vahid chakoshy solutions:
#!/usr/bin/env bash
if [ "$#" -eq 2 ]; then
echo "$(echo "scale=2; $(curl https://api.github.com/repos/$1/$2 2>/dev/null \
| grep size | head -1 | tr -dc '[:digit:]') / 1024" | bc)MB"
elif [ "$#" -eq 3 ] && [ "$1" == "-z" ]; then
# For some reason Content-Length header is returned only on second try
curl -I https://codeload.github.com/$2/$3/zip/master &>/dev/null
echo "$(echo "scale=2; $(curl -I https://codeload.github.com/$2/$3/zip/master \
2>/dev/null | grep Content-Length | cut -d' ' -f2 | tr -d '\r') / 1024 / 1024" \
| bc)MB"
else
printf "Usage: $(basename $0) [-z] OWNER REPO\n\n"
printf "Get github repository size or, optionally [-z], the size of the zipped\n"
printf "master branch (`Download ZIP` link on repo page).\n"
exit 1
fi
You can do it using the Github API
This is the Python example:
import requests
if __name__ == '__main__':
base_api_url = 'https://api.github.com/repos'
git_repository_url = 'https://github.com/garysieling/wikipedia-categorization.git'
github_username, repository_name = git_repository_url[:-4].split('/')[-2:] # garysieling and wikipedia-categorization
res = requests.get(f'{base_api_url}/{github_username}/{repository_name}')
repository_size = res.json().get('size')
print(repository_size)
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.