4 ms·
Ask HN: Getting a single file from a public GitHub repo?
Let's say I have a public GitHub repo called Notes
The entire repo is only a Readme file, and a folder with 20 text files.
Is it possible to list the 20 text files and download one. If possible I'd love to do this via a Rest API, and without cloning the whole repo.
- deleted 4y ago[deleted]
- verdverm 4y agoYou can get a single file, but you cannot list them, afaik, maybe I'm wrong? Cloning is not that expensive, consider how many deps you fetch in a typical day. I actually do this to fetch initial / bootstrap content stored in a repo, and hold it in memory without the need to write it. I am considering changing this and exec'n out to git as a more secure / standard practice
- 999900000999 4y agoI'm thinking you could probably configure GitHub pages to return JSON. And then you'd have a call which would basically return a listing of all the files, along with the URLs to get them.
- verdverm 4y agoAt that point, why not just put the listing as a file in the repo and just fetch that directly?
- 999900000999 4y agoI'd have to generate that file and commit it though.
- verdverm 4y agoah, you mean GHP producing something like a sitemap.json for your repo, hmmmmm
- 999900000999 4y agoExactly, I want to use the Git repo as a read only REST API.
- verdverm 4y agoYou could always use something like S3 or GCS if GHP doesn't work
- NonEUCitizen 4y agoFor downloading a single file, I do it manually by clicking on the "Raw" button the using Copy/Paste. The raw button leads to a url starting with "https://raw.githubusercontent.com/ https://raw.githubusercontent.com/" If that url is stable, then presumably I could've used wget instead of manual copy/paste.