108

Is there any way to get how many times a git repository has been cloned or downloaded from github? I was just curious as I found other statistics such as commit times lines of code can be generated using: http://gitstats.sourceforge.net/ but I did not find how to check for clone/download count.

starball
  • 20,030
  • 7
  • 43
  • 238
Shreyas Karnik
  • 3,953
  • 5
  • 27
  • 26
  • Would you like to find out how many times a repository has been ***forked*** instead? Because that is definitely doable. –  May 09 '14 at 19:29
  • 1
    You now can see the **number of clones**: see [How to get GitHub Clone stats?](http://stackoverflow.com/a/25270050/6309) – VonC Aug 12 '14 at 17:10
  • 1
    possible duplicate of [How to get GitHub Clone stats?](http://stackoverflow.com/questions/10056638/how-to-get-github-clone-stats) – sumid Sep 12 '14 at 13:11

6 Answers6

124

Its super easy now!

Go "REPO -> Insights -> Traffic"

enter image description here

Farhan
  • 3,162
  • 3
  • 25
  • 17
  • 2
    just a note, this seems to require that you have some level of "ownership" or commiter level access – bbarker Feb 02 '18 at 16:11
  • 4
    @KevinWorth The OP specifically mentioned github in his question. And tagged github. Perhaps you didn't read the full question, or look at it's tags? – csga5000 Apr 02 '18 at 20:06
  • 7
    Awesome - it shows last 30 days statistics. It would be nice if they had all time or by year, but this is something! – TetraDev Aug 03 '18 at 23:37
  • Note that to enable this feature the repository has to be public, or you have to have to Pro account – SilentCloud Oct 14 '21 at 09:22
  • It's great to have it, unfortunately it's limited to 14-days past statistics. There's been a great solution that works to overcome that limitation and persists some data https://github.com/jgehrcke/github-repo-stats – unacorn Mar 27 '23 at 16:26
33

Cloning is a read-only operation, the original repository isn't modified. There is no way you can pull statistics for data that simply isn't tracked.

user229044
  • 232,980
  • 40
  • 330
  • 338
  • 25
    Well, it would be *possible* to track it outside of git, by logging at the level of the transport mechanism. For example, I'm pretty sure gitolite logs would provide enough information to deduce clones (although I think they might not be distinguishable from fetching all refs a different way? don't have any to look at here). But of course, you don't have access to that kind of thing from github, even if it exists. – Cascabel Jul 15 '11 at 00:49
  • Never mind that clones are full repositories that can themselves be cloned. Seeing how many times a particular instance of a repository has been cloned wouldn't be useful for figuring out how many people have cloned it universally. – user229044 Jul 16 '11 at 18:20
  • 31
    Yeah, it certainly wouldn't ever be a reliable statistic, but for example, I could see an open source project being curious to at least have an order of magnitude estimate of how many people might be building from development master instead of stable snapshots. – Cascabel Jul 16 '11 at 22:08
  • 1
    I think they could just log the git clone requests ammount; or even better, these requests that actually complete the download. – Aquarius Power Nov 24 '14 at 16:20
  • With the `github.com` servicing dom it still can not be reached at least without a private token. See details here: https://github.com/MShawon/github-clone-count-badge – Andry Oct 26 '21 at 11:01
16

I just find out there is an even simpler way to get it with a single command using the github API.

curl -u [username]:[password] https://api.github.com/repos/[owner]/[repo]/traffic/clones

here:

username  = your github id
password  = your github password, optional. If not put in command, a password request would pop out.
owner     = the owner of the repo, might be another name for a organized repo
repo      = the repo name

Have fun.

Wei Song
  • 545
  • 3
  • 11
  • 1
    ```"message": "Not Found", "documentation_url": "https://docs.github.com/rest/reference/repos#get-repository-clones" ``` – SuperCode Jul 28 '21 at 19:43
7

Regarding download statistics, you can get information about your Releases via the API.

For those using WordPress, I developed this plugin: GitHub Release Downloads. It allows you to get the download count, links and more information for releases of GitHub repositories.

To address the original question, the shortcode [grd_count user="User" repo="MyRepo"] will return the number of downloads for a repository. This number corresponds to the sum of all download count values of all releases for one GitHub repository.

Example: Example

IvanRF
  • 7,115
  • 5
  • 47
  • 71
2

You can use shields.io which provides icon bars that displays counts for projects in various websites including Github. They display the download counts, but not the clone counts.

Here's an example for a project I have:

Markdown Code:

![GitHub All Releases](https://img.shields.io/github/downloads/lewdev/hw-gen/total)

Result:

GitHub All Releases

Nobody "downloads" my app because it's already published, but people do clone it. So I'd rather see the counts for that.

Lewis Nakao
  • 7,079
  • 2
  • 26
  • 21
1

Actual clone counts are available via the Clone Graphs feature, which I've been able to scrape to get the individual counts:

#!/bin/sh
#
# This script requires:
#   apt-get install html-xml-utils
#   apt-get install jq
#
USERNAME=dougluce
PASSWORD="PASSWORD GOES HERE, BE CAREFUL!"
REPO="dougluce/node-autovivify"

TOKEN=`curl https://github.com/login -s -c /tmp/cookies.txt | \
     hxnormalize | \
     hxselect 'input[name=authenticity_token]' 2>/dev/null | \
     perl -lne 'print $1 if /value=\"(\S+)\"/'`

curl -X POST https://github.com/session \
     -s -b /tmp/cookies.txt -c /tmp/cookies2.txt \
     --data-urlencode commit="Sign in" \
     --data-urlencode authenticity_token="$TOKEN" \
     --data-urlencode login="$USERNAME" \
     --data-urlencode password="$PASSWORD" > /dev/null

curl "https://github.com/$REPO/graphs/clone-activity-data" \
     -s -b /tmp/cookies2.txt \
     -H "x-requested-with: XMLHttpRequest" #| jq '.summary'
Allen Luce
  • 7,859
  • 3
  • 40
  • 53