GitHub: finding the oldest commit on large repositories
Posted by jpluimers on 2025/06/25
The manual process of getting back to the earliest commit of a GitHub repository is easy for small repositories, but for a large one it is very tedious.
TL;DR: there are various ways, but the easiest was the INIT Bookmarklet below.
Note: 2 weeks before the scheduled post made it to the front of the queue, I got a report¹ that it started to fail. Here it still works.
It’s hard to debug because of the functional programming approach taken.
A few of the repositories I tried this on (all returning the first commit within seconds):
- 500 commits at github.com/wabarc/wayback finding github.com/wabarc/wayback/commit/650ea87200a5f3dad1e2a96ebf69e08083cca5d0
- 10k commits at github.com/rustdesk/rustdesk finding github.com/rustdesk/rustdesk/commit/35b260e13a7b135f0a9844c27a05316eceeadbcd (this was for On my list of tools to check out RustDesk (as replacement for TeamViewer, Remote Desktop and similar))
- 140k commits at github.com/dotnet/runtime finding github.com/dotnet/runtime/commit/480e91e54517a0fee2e64a9a24dc8319dad03186
The reason that INIT works is that it is based on the GitHub API. Virtually all other Bookmarklets are based on the modern version of old Screen Scraping: Web Scraping. They fail over time because of the same reason Screen Scraping was so fragile: the underlying UI changes, then breaks the scraping mechanism.
Not having enough JavaScript debugging knowledge, the only drawback for me of the INIT approach is that it uses functional programming: besides adding logging statements I have no idea how to debug it, so when it fails, it is tough¹.
The query that led me to this quest was [Wayback/Archive] github find initial commit of repository – Google Search
Solutions I tried:
- Manual cloning, then
git log --reversebased solutions: time consuming - Using the Insights link: it takes forever to load the histogram on large repositories.
- UI based scraping bookmarklets – they all fail over time and most are unmaintained
- The INIT bookmarklet which is based on the Google API
INIT Bookmarklet links:
- [Wayback/Archive] raw.githubusercontent.com/FarhadG/init/refs/heads/master/src/index.js raw non-minified Bookmarklet code
- [Wayback/Archive] init/src/index.js at master · FarhadG/init · GitHub non-minified syntax highlighted Bookmarklet code
- [Wayback/Archive] Init: A quick way to go to the first commit of a repo the Gulp.js template based web page to install the minified Bookmarklet from (GitHub thinks it is Smarty based, but it is indeed Gulp.js based)
- [Wayback/Archive] GitHub – FarhadG/init: :exclamation: Go to the first (initial) commit of any GitHub repo
- [Wayback/Archive] Not working · Issue #18 · FarhadG/init where [Wayback/Archive] TechMorgan · GitHub commented
I just checked the bookmarklet and it worked. I think it only fails sometimes. This script doesn’t work on private repos.
and I responded:
The “doesn’t work on private repos” is likely because of the Git API usage (it does plain access without an API key).
Could you please add this limitation to the README.md then issue a pull request for that README change?
and [Wayback/Archive] cachius · GitHub with:
The INIT bookmarklet uses the link response header of the commits endpoint which looks like
link: <https://api.github.com/repositories/205423/commits?sha=&page=2>; rel="next", <https://api.github.com/repositories/205423/commits?sha=&page=1139>; rel="last"Maybe the GitHub API behaves abnormally when it fails. (via)
having these links:
- [Wayback/Archive] init/src/index.js at f532e8e2fad8edb3a79804e3ab21a2dae7ffc1a2 · FarhadG/init · GitHub – Line 12
.then(res => Promise.all([res.headers.get('link'), res.json()])) - [Wayback/Archive] Using pagination in the REST API – GitHub Docs: using
linkheaders
When a response is paginated, the response headers will include alinkheader. If the endpoint does not support pagination, or if all results fit on a single page, thelinkheader will be omitted.Thelinkheader contains URLs that you can use to fetch additional pages of results. For example, the previous, next, first, and last page of results.To see the response headers for a particular endpoint, you can use curl, GitHub CLI, or a library you’re using to make requests. To see the response headers if you are using a library to make requests, follow the documentation for that library. To see the response headers if you are using curl or GitHub CLI, pass the--includeflag with your request. For example:curl --include --request GET \ --url "https://api.github.com/repos/octocat/Spoon-Knife/issues" \ --header "Accept: application/vnd.github+json"If the response is paginated, thelinkheader will look something like this:link: <https://api.github.com/repositories/1300192/issues?page=2>; rel="prev", <https://api.github.com/repositories/1300192/issues?page=4>; rel="next", <https://api.github.com/repositories/1300192/issues?page=515>; rel="last", <https://api.github.com/repositories/1300192/issues?page=1>; rel="first"Thelinkheader provides the URL for the previous, next, first, and last page of results:- The URL for the previous page is followed by
rel="prev". - The URL for the next page is followed by
rel="next". - The URL for the last page is followed by
rel="last". - The URL for the first page is followed by
rel="first".
- The URL for the previous page is followed by
- [Wayback/Archive] REST API endpoints for commits – GitHub Docs
- [Wayback/Archive] github – How to navigate to the earliest commit in a repository? – Stack Overflow: comment
- [Wayback/Archive] init/src/index.js at f532e8e2fad8edb3a79804e3ab21a2dae7ffc1a2 · FarhadG/init · GitHub – Line 12
- a
The below GreasyFork Greasemonkey userscript has a solution very similar to the above INIT one:
- [Wayback/Archive] GreasyFork: GitHub First Commit
- [Wayback/Archive] GreasyFork: GitHub First Commit – Source code
- [Wayback/Archive] GitHub – chocolateboy/userscripts: Userscripts for Greasemonkey, Tampermonkey etc.
- [Wayback/Archive] userscripts/src/github-first-commit.user.ts at master · chocolateboy/userscripts · GitHub
- [Wayback/Archive] raw.githubusercontent.com/chocolateboy/userscripts/refs/heads/master/src/github-first-commit.user.ts
Things I tried were based on:
- [Wayback/Archive] github – How to navigate to the earliest commit in a repository? – Stack Overflow (thanks [Wayback/Archive] jdw, [Wayback/Archive] Stevoisiak and [Wayback/Archive] cachius)
Is there an easy way to navigate to the earliest commit of a large open-source project in GitHub?
The project has over 13,000 commits as of today. I don’t want to press the “Older” button on the commit history page hundreds and hundreds of times to get to the initial commit (or first commit).
has all kinds of manual solutions, most depending on
git log --reverseand many bumping in it’s limitations (like it not liking other arguments causing unreliable output) requiring piping output through other tools.
Some quotes:
- Clone the repository, open with the command line and run
$ git log --reverseThis will show the commits in reverse order.Then you can view it on github once you have the ID(Object Name) of the first commit … something like…https://github.com/UserName/Repo/commit/6a5ace7b941120db5d2d50af6321770ddad4779e - I got weird results when I tried to get just the first commit of a repo with
git log --reverse -n 1. Well not weird, it just ignored the--reverseflag on git2.46.2 - ² @andrewarchi Nicely done. Actually the first few commits are easter-eggs: stackoverflow.com/a/21981037/6309
- On project page click tab
Insights > Contributors. Select the beginning of the histogram. Click the commits number. Done.
Mentioned Bookmarklets or derivatives that do not function any more
- Clone the repository, open with the command line and run
- [Wayback/Archive] How do I find the date of the first commit in a GitHub repository? – Web Applications Stack Exchange has similar answers suggesting
git log --reverseand the Insights link (with similar results: failing, slow or tedious) with one exception: the GitHub API has a very easy way to get the creation date of a github repository. That usually is close to the first commit:
A quick technique that worked for me was to just use curl with the GitHub API to determine the repo’s creation date. It won’t be as accurate as the first commit date for forks or other situations where the project was started before the repo was created (e.g. started on GitLab and then imported).
The syntax I used for this was:
curl -s https://api.github.com/repos/[username]/[repository-name] | jq '.created_at'.So I commented this:
Note this is the creation timestamp of the repository, not the first commit. Usually these are not far apart, but they are distinctly different. For instance github.com/dotnet/runtime
2019-09-24T23:36:39Z, the first commit is github.com/dotnet/runtime/commit/480e91e54517a0fee2e64a9a24dc8319dad03186 which got created at2001-06-19T03:37:46Z. There is only about a minute between them, but still.Because of this query:
curl -s https://api.github.com/repos/dotnet/runtime/commits/480e91e54517a0fee2e64a9a24dc8319dad03186 | jq '.commit.committer.date'
“Footnotes”
¹ [Wayback/Archive] @JeroenWiertPluimers The ‘Init’ bookmarklet by FarhadG broke shortly after your comment and is still broken as of June 2025. – by [Wayback/Archive] cachius
- [Wayback/Archive] github – How to navigate to the earliest commit in a repository? – Stack Overflow – answer with INIT bookmarklet by Stevoisiak (thanks [Wayback/Archive] Stevoisiak)
- [Wayback/Archive] Not working · Issue #18 · FarhadG/init where I mentioned my debugging problems.
If that gist keeps failing, I should try these answers from the same question:
- [Wayback/Archive] github – How to navigate to the earliest commit in a repository? – Stack Overflow – answer by Tuan Anh Tran (thanks [Wayback/Archive] Tuan Anh Tran) which uses the API based approach and does some logging:
You can use this gist to create a bookmarklet.
The code
async function goToFirstCommit(owner, repo) { const headers = { "Accept": "application/vnd.github.v3+json", // Optional: Add authorization if you hit the rate limit (use a personal access token) // "Authorization": "Bearer YOUR_GITHUB_TOKEN" }; const repoInfo = await fetch(`https://api.github.com/repos/${owner}/${repo}`, { headers }); const repoData = await repoInfo.json(); const defaultBranch = repoData.default_branch; const branchInfo = await fetch(`https://api.github.com/repos/${owner}/${repo}/branches/${defaultBranch}`, { headers }); const branchData = await branchInfo.json(); const latestCommitSha = branchData.commit.sha; // Step 2: Get the total number of commits in the default branch using the API for commits count const commitsInfo = await fetch(`https://api.github.com/repos/${owner}/${repo}/commits?sha=${defaultBranch}&per_page=1`, { headers }); const linkHeader = commitsInfo.headers.get("link"); // The "last" page link in the Link header contains the total number of commits let totalCommits; if (linkHeader) { const lastPageMatch = linkHeader.match(/&page=(\d+)>; rel="last"/); totalCommits = lastPageMatch ? lastPageMatch[1] : 1; } else { // If there's no pagination, it means there is only one page of commits totalCommits = 1; } console.log(`Total commits in ${defaultBranch} branch: ${totalCommits}`); if (totalCommits != 1) { const firstCommitURL = `https://github.com/${owner}/${repo}/commits/${defaultBranch}/?after=${latestCommitSha}+${totalCommits - 36}` console.log(`First commit URL is ${firstCommitURL}`) window.location.href = firstCommitURL; } } async function main() { const currentUrl = window.location.href; const regex = /https:\/\/github\.com\/([^\/]+)\/([^\/]+)/; const match = currentUrl.match(regex); if (match) { const owner = match[1]; const repo = match[2]; console.log(`Owner: ${owner}`); console.log(`Repository: ${repo}`); await goToFirstCommit(owner, repo); } else { console.log("Not on a GitHub repository page."); } } main()It only works for public repo for now since I use github api to find latest sha & total commits.
Use this website to create bookmarklet
Links:
- [Wayback/Archive] github – How to navigate to the earliest commit in a repository? – Stack Overflow – answer by Dwza (thanks [Wayback/Archive] Dwza)
I don’t know if this just possible nowadays but you can just call the correct link :)
Repo
https://github.com/{owner}/{repo}/commitsThis should actually list all commits, starting with the latest (or earliest… it’s the most recent).
For example, lets take shopware – See repo commits
https://github.com/shopware/shopware/commitsSpecific Branch
This also works for specific branches e.g.
https://github.com/{owner}/{repo}/commits/{branch}Staying with shopware – See branch specific commits
https://github.com/shopware/shopware/commits/6.5.xSo there are no needs of any kind of scripts, crazy long functions or so.
Links:
- [Wayback/Archive] https://github.com/shopware/shopware/commits
- [Wayback/Archive] https://github.com/shopware/shopware/commits/6.5.x
First commit page and first commit (which is identical for the main branch, in this case
trunk, and the branch6.5.x):
² Early Go programming language commits: [Wayback/Archive] mercurial – What’s the story behind the revision history of Go? – Stack Overflow with a few puns starring Brian Kernighan, the C programming language, and ANSI C.
--jeroen






Leave a comment