How to get all of a user's public github commits

http://zmoazeni.github.com/gitspective/ is your friend. :-) Filter out all but "Push", and you have your view, albeit without the coding work to implement it yourself first.

Inspecting what goes on with the Chrome Devtools "Network" tab might help you mimic the API queries, if you want to redo the work yourself.


The correct way to do this is via the Events API.

First you need to fetch the user's events:

GET /users/:username/events

Then you will want to filter the response array for items where type is set to PushEvent. Each one of these items corresponds to a git push by the user. The commits from that push are available in reverse chronological order in the payload.commits array.

The next step is to filter out commits made by other users by checking the author.email property of each commit object. You also have access to properties like sha, message and url on the same object, and you can eliminate duplicate commits across multiple pushes by using the distinct property.

EDIT: As pointed out by Adam Taylor in the comments, this approach is wrong. I failed to RTFM, sorry. The API lets you fetch at most 300 events and events are also limited to the last 90 days. I'll leave the answer here for completeness but for the stated question of fetching all commits, it won't work.


UPDATE 2018-11-12

The URLs mentioned below have now moved to a single URL that looks like https://github.com/AurelienLourot?from=2018-10-09 but the idea remains the same. See github-contribs.


I'd like to know if there's an easy way of getting all commits to all public repositories for a single username.

The first challenge is to list all repos a user has ever contributed to. As pointed out by others, the official API won't allow you to get this information since the beginning of time.

Still you can get that information by querying unofficial pages and parsing them in a loop:

  • https://github.com/users/AurelienLourot/created_commits?from=2018-05-17&to=2018-05-17
  • https://github.com/users/AurelienLourot/created_repositories?from=2018-05-17&to=2018-05-17
  • https://github.com/users/AurelienLourot/created_pull_requests?from=2018-05-17&to=2018-05-17
  • https://github.com/users/AurelienLourot/created_pull_request_reviews?from=2018-05-17&to=2018-05-17

(Disclaimer: I'm the maintainer.)

This is exactly what github-contribs does for you:

$ sudo npm install -g @ghuser/github-contribs
$ github-contribs AurelienLourot
✔ Fetched first day at GitHub: 2015-04-04.
⚠ Be patient. The whole process might take up to an hour... Consider using --since and/or --until
✔ Fetched all commits and PRs.
35 repo(s) found:
AurelienLourot/lsankidb
reframejs/reframe
dracula/gitk
...