537

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.

Gonçalo Peres
  • 11,752
  • 3
  • 54
  • 83
jhabbott
  • 18,461
  • 9
  • 58
  • 95
  • 2
    possible duplicate of [Is it possible to remote count object and size of of git repository?](http://stackoverflow.com/questions/2882620/is-it-possible-to-remote-count-object-and-size-of-of-git-repository) – kennytm Dec 27 '11 at 15:56
  • 5
    @KennyTM very similar question, yes, but this is specific to github rather than any method using only the git protocol. – jhabbott Dec 27 '11 at 16:03
  • 3
    FYI, check out this chrome extension which automatically adds repository size to GitHub's repository summary https://github.com/harshjv/github-repo-size. **UPDATE: added this as an answer** – Harsh Vakharia Aug 03 '16 at 19:40
  • Here's a hint: My absolute largest repository contains only images of various formats, it's an "artwork" repo of icons which I use in various apps. Yet, GitHub reports the size as 0. So I'm assuming it only considers the size of known source files, and doesn't consider unknown file types. – Jerry Dodge Jun 14 '19 at 19:27
  • 3
    After seeing the immense popularity of this question, I created a website for this exact purpose. Checkout [here](https://citizendot.github.io/gh-info/). – Appaji Chintimi Jun 24 '21 at 10:10

14 Answers14

409

There's a way to access this information through the GitHub API.

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.

Update

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.

iBug
  • 35,554
  • 7
  • 89
  • 134
nulltoken
  • 64,429
  • 20
  • 138
  • 130
  • @FrançoisBeaune yes its MB. – Mike Graf Jan 14 '13 at 17:25
  • 14
    Isn't the size in MB now -> It's not that clear, it looks like it depends on the repo being queried... Small repos expose size in bytes, large ones in megabytes. I've opened an issue at GitHub support. I'll update the answer as soon as the issue is closed. – nulltoken Jan 14 '13 at 18:57
  • 9
    This doesn't seem to work for private repos. Am I missing something? Thanks! – nroose Jan 17 '14 at 21:42
  • 25
    @nroose Try `$ curl -u "{:username}" https://api.github.com/repos/{:organization}/{:repository}`. See https://developer.github.com/v3/#authentication – nulltoken Feb 07 '14 at 07:09
  • 1
    @nulltoken Any response on the query about kB / MB etc? – nealmcb Jun 13 '17 at 19:43
  • 3
    Just forked a repo (September 9th, 2018) and it's kB, not MB – Jacob Stamm Sep 07 '18 at 13:09
  • e.g. the `php/php-src` repo is reported to be `"size": 362064,`, while my file manager says it's 501 MB. looks like it's KB. – whyer Apr 16 '19 at 14:06
  • 4
    Came here looking for an answer as to why the GitHub API returns WAY less than the actual downloaded repo. Turns out this file size (which the API doesn't clearly document but appears to be in KB) is not very reliable. – Jerry Dodge Jun 04 '19 at 01:00
  • PS - I guess that also explains why anything which can download a Repo via ZIP is unable to get the header with the file size... It builds the file on the fly... – Jerry Dodge Jun 04 '19 at 01:24
  • Here's a hint: My absolute largest repository contains only images of various formats, it's an "artwork" repo of icons which I use in various apps. Yet, GitHub reports the size as 0. So I'm assuming it only considers the size of known source files, and doesn't consider unknown file types. – Jerry Dodge Jun 14 '19 at 19:28
  • example: https://api.github.com/repos/date-fns/date-fns look for "size" property, in this case it's 11124 kb, which is 10.86 mb. Or, you can use Chrome extension described below by @Bigwave. – W. Elbashier Jul 03 '19 at 16:25
  • @nulltoken The size is in KB. – Shimmy Weitzhandler Oct 07 '20 at 13:52
231

If you own the repository, you can find the exact size by opening your Account SettingsRepositories (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.

yuranos
  • 8,799
  • 9
  • 56
  • 65
CoatedMoose
  • 3,624
  • 1
  • 20
  • 36
  • Shouldn't one take into account the zip compression? Source code and text files can be compressed upto about 60% I think. – ffledgling Feb 17 '13 at 21:14
  • I am unaware of a way to check the compression ratio of the zip without completing the download. Of course you could complete the download and then check the compression ratio. However, at that point, you might as well unzip and check the repo size directly. It really depends on how accurate you need to be. And if you can afford to download the repo to check. – CoatedMoose Sep 16 '13 at 05:48
  • 4
    I could not find it in `Settings > Repositories`, but instead found the repo size under `Account Settings > Repositories` off of your git home page. Of course, this only works with repos that you own (or fork). – modulitos Jun 18 '14 at 18:44
  • 3
    Organizations' account settings do not appear to show repo size, so it is only if you own a repo as a user and not as an organization? – Bennett Brown Oct 31 '14 at 15:20
  • @BBrown If you can see the repo, you can always fork it and see it that way. – CoatedMoose Nov 18 '14 at 22:44
  • 2
    Can't view the size of private repos, grr – rw-nandemo Feb 08 '15 at 04:38
  • The "download as a zip file" option in GitHub is actually a bit different: seems to me that it only downloads the master branch, while the former method you have indicated measures the (compressed) size of all branches. – Danilo Pianini Sep 01 '15 at 15:26
  • 4
    The size of the zip file is *no indication at all* of the actual repository size: 1) it only includes a snapshot of the repository at a given revision with no history and 2) Git repositories are stored as pack files which are compressed, do not store duplicates etc. – kynan Oct 08 '15 at 22:50
  • In addition, the ZIP file is built on-the-fly, so there's no way of getting the size of the repo before-hand. You'd have to wait for the file to finish downloading, then read it. But of course, compressed data is unreliable information. – Jerry Dodge Jun 14 '19 at 19:29
  • This is such an easy method and shows the exact size. Thanks:) – Haardik Dharma Aug 19 '20 at 05:50
  • How... inconvenient – Randall Coding Apr 18 '21 at 20:10
120

If you use Google Chrome browser you can install the GitHub Repository Size extension.

enter image description here

Repo here: https://github.com/harshjv/github-repo-size

Gabriel
  • 40,504
  • 73
  • 230
  • 404
Bigwave
  • 2,166
  • 1
  • 17
  • 28
  • 7
    any firefox port? – Banee Ishaque K Jul 23 '17 at 06:53
  • 3
    @BaneeIshaqueK its not the same but it does show you the repo size check it [here](https://addons.mozilla.org/en-US/firefox/addon/github-repo-size/) – Syed Shamikh Shabbir Dec 02 '17 at 16:22
  • 1
    ***UPDATE*** Now, works perfectly even in private repositories as long as you provide the Github token. – Siddhant Rimal May 11 '18 at 12:05
  • 6
    Still not reliable, it uses the GitHub API, which does not report correct size. I have a repository with nothing but images (no code), and the API reports the size as 0, although it's the largest repo I have. This extension doesn't even show me the size of this particular repo (probably because it sees 0). – Jerry Dodge Jun 15 '19 at 16:59
40

@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.

A private repo requires authentication. One way is with a GitHub Personal Access token:

curl -u myusername:$PERSONAL_ACCESS_TOKEN https://api.github.com/repos/$2/$3 2> /dev/null | grep size | tr -dc '[:digit:]'
mmell
  • 2,448
  • 1
  • 24
  • 16
trevorrobertsjr
  • 705
  • 7
  • 6
30

From a browser, with JavaScript, since the Github API is CORS enabled:

fetch('https://api.github.com/repos/webdev23/source_control_sentry')
  .then(v => v.json()).then((v) => {
     console.log(v['size'] + 'KB')
  }
)
NVRM
  • 11,480
  • 1
  • 88
  • 87
  • 3
    Love this answer. Only takes seconds to get the size. – Dan Swain Sep 28 '21 at 18:30
  • 5
    Curl? Browser extensions? NVRM's answer is literally the best one on this thread. Highly underrated. Thanks NVRM! – eFail Oct 12 '21 at 23:27
  • It says `{ "message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#get-a-repository" }` – RegarBoy Dec 19 '21 at 16:46
  • 1
    The best answer!❤️ – mdmundo Mar 17 '22 at 17:50
  • very very good. Little more readable with MB conversion fetch('https://api.github.com/repos/aws/aws-toolkit-vscode') .then(v => v.json()).then((v) => { console.log(v['size'] /1000 + 'MB') } ) – Carlo Jul 16 '22 at 12:31
  • how to change the url in order to read my repo ? @NVRM – Ae Leung Mar 09 '23 at 11:46
  • I'd like to measure in MB: `fetch('https://api.github.com/repos/webdev23/source_control_sentry') .then(v => v.json()).then((v) => { console.log(Math.round((v['size'] / 1024)*100)/100 + ' Mb') } ) ` – Ibrahim.H Mar 12 '23 at 06:47
24

If you're trying to find out the size of your own repositories.

All you have to do is go to GitHub settings repositories and you see all the sizes right there in the browser no extra work needed.

https://github.com/settings/repositories

Nathan Weiler
  • 407
  • 4
  • 4
11

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
larowlan
  • 159
  • 1
  • 3
8

As shown in other answers, it's possible to get a size via api.github.com. It's in the size property of a JSON object returned.

To get it, just add to your repo URL an additional subdomain api and extend the repo path with /repos:

# For public repos ->
#     Repo example: Axios
#     Repo URL: https://github.com/axios/axios
        
             ⤵              ⤵
curl https://api.github.com/repos/axios/axios

# For private repos ->
#   Repo example: My-repo
#   Repo URL: https://github.com/my-org/my-repo

curl https://{username}:{api-token}@api.github.com/repos/{orgname}/{reponame}

As it's only URL, you can fetch data using any programming language.

The response will be like:

// Much more props inside
{
  "id": 23088740,
  "name": "axios",
  "full_name": "axios/axios",
  "private": false,
  "size": 4396,
  "default_branch": "v1.x",
  "visibility": "public",
  "network_count": 9581,
  "subscribers_count": 1213
}

The most important to us is size. It's in Kb now, but it could be changed in the future (as it was already).

But... I tested it a lot of times, and see that real size of repo and the size shown with the above mechanism are too different.

Let's give the same axios repo:

  • the size shown in api.github.com -> 4396 Kb -> ~4.29 Mb

What if clone a full repo:

  • pull the repo with clone repo.git command
  • get weight with command du -sh ./axios
  • have -> 8.0 Mb
  • remove .git folder from inside
  • have -> 2.6 Mb

not good, as size ~4.29 Mb is not 8 or 2.6 Mb either

What if clone only the latest commit:

  • pull the repo with --depth 1 flag, like clone repo --depth 1
  • get weight with command du -sh ./axios
  • have -> 3.2 Mb (that's close)
  • remove .git folder from inside
  • have -> same 2.6 Mb

not good, as size ~4.29 Mb is not 3.2 or 2.6 Mb either

What if clone only one branch:

  • in the above JSON we have a param, called default_branch. Let's clone
  • pull the repo with -b v1.x --single-branch flags
  • get weight with command du -sh ./axios
  • have -> 7.5 Mb (that's close)
  • remove .git folder from inside gives the same 2.6 Mb

still not good, as size ~4.29 Mb is not 7.5 or 2.6 Mb either

Thus, the size param shows something, that is close to the latest commit, but it's not the strongly right size of the repo.

I have shown above how it works with axios repo, but tests with different repos show the same results.

That's from my experience.

woolfi makkinan
  • 189
  • 1
  • 3
4

If you have the official GitHub CLI installed, you can do the following:

gh api repos/<org>/<repo> --jq '.size'

I think it reports the size in KBs.

Emily
  • 2,577
  • 18
  • 38
3

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:

  1. :owner - the username of the person who owns the repository
  2. :repository - The name of the repository

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
  • 1
    A) As many are reporting, this size is not accurate and not reliable. B) Even if it was, your note(s) about visually reading the JSON, the line number, and formatting... all pointless. JSON isn't meant for humans to read, it's meant for computers to read. You should be mentioning to read the `size` key in the response, not line 78. Not to mention, different formatters will have different line breaks in different places, leaving desired data at a different line number. – Jerry Dodge Jun 14 '19 at 19:34
  • @JerryDodge first thing you should carefully read the answer I have mentioned ``` you should see a key named size ``` and I said you should ```probably```see it on line no 78,so that indicates you should see the size key somewhere around 78, second thing if the size from the github apis was not accurate,I dont think you will find something more accurate than github apis. – Mahesh Jamdade Mar 26 '20 at 03:52
  • 2
    I have a repository of images. Images are binary data. There are no text files in this repo at all. GitHub reports everywhere that it consumes 0 bytes. Even the website / plugin. – Jerry Dodge Mar 28 '20 at 11:12
3

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)
Alon Barad
  • 1,491
  • 1
  • 13
  • 26
2

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
golem
  • 1,820
  • 1
  • 20
  • 25
2

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.

Mike Godin
  • 3,727
  • 3
  • 27
  • 29
2

I created a bookmarklet script to do this using the method from NVRM's Answer.

To use it, create a new bookmark, give it name, and paste this script into the URL field. Clicking on this bookmark while browsing a repo pops an alert with that repo's size in both megabytes and kilobytes.

javascript:(()=>{let url=new URL(document.location.href);if(url.origin!="https://github.com"){return}if(url.pathname=="/"){return}let p=url.pathname.slice(1,url.pathname.length);let parts=p.split('/');if(parts.length<2){return}let x=[parts[0],parts[1]].join('/');fetch(`https://api.github.com/repos/${x}`).then(r=>r.json()).then((b)=>alert(`${(b['size']/1000).toFixed(2)}mb (${b['size']}kb)`))})()
Besworks
  • 4,123
  • 1
  • 18
  • 34