102

I want to learn how to use rawgit.com to serve other applications from github.com. So we have a usual way to download and install homebrew on osx.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

I can't find the install file on GitHub. Where is it?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
megas
  • 21,401
  • 12
  • 79
  • 130
  • Are you asking us to explain how that install command works? Have you looked at the contents of the file referenced on `raw.githubusercontent.com`? Have you looked at the documentation for `curl`? Do you know what `$()` does in the shell? Do you know what `ruby -e` does? – ChrisGPT was on strike Aug 21 '16 at 16:30
  • I can't find 'install' file in repository, that's i asked this quitstion – megas Aug 21 '16 at 16:40
  • 1
    Please note that rawgit.com is _not_ an alias for raw.githubusercontent.com. It is a third party service not affiliated to GitHub. – GOTO 0 Oct 03 '18 at 14:49
  • 3
    Also RawGit is at or near end-of-life; see https://rawgit.com/ – TrueWill Dec 26 '18 at 17:30

3 Answers3

125

The raw.githubusercontent.com domain is used to serve unprocessed versions of files stored in GitHub repositories. If you browse to a file on GitHub and then click the Raw link, that's where you'll go.

The URL in your question references the install file in the master branch of the Homebrew/install repository. The rest of that command just retrieves the file and runs ruby on its contents.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 1
    My assumption was that install script locates in main repository, thanks – megas Aug 21 '16 at 16:53
  • 6
    What does "unprocessed versions of files" mean pls ? – Tristan Jun 08 '17 at 13:20
  • 8
    @Tristan, it means you'll see the contents of the file without any GitHub UI, and files that typically get rendered (e.g. Markdown) won't be. You just see the raw text content of the file. – ChrisGPT was on strike Jun 08 '17 at 13:58
  • If I use GitHub public repo to store JSON files and be read from other places. **Should I use `raw.githubusercontent` or `GitHub pages` ?** I'm currently using `GitHub pages` link, it is shorter. But in case of re-upload I sometimes needed to wait a bit for `GitHub pages` to re-update itself. So **what people usually do?** – zummon Oct 05 '21 at 09:12
  • 2
    @zummon, that depends entirely on your use case and is pretty opinion-based. But if the _only_ reason for that repository is to host JSON files that get consumed elsewhere, I wouldn't personally set up a Pages site. Not sure why the length of the URL makes any difference. – ChrisGPT was on strike Oct 05 '21 at 11:57
46

There are two ways of looking at github content, the "raw" way and the "Web page" way.

raw.githubusercontent.com returns the raw content of files stored in github, so they can be downloaded simply to your computer. For example, if the page represents a ruby install script, then you will get a ruby install script that your ruby installation will understand.

If you instead download the file using the github.com link, you will actually be downloading a web page with buttons and comments and which displays your wanted script in the middle -- it's what you want to give to your web browser to get a nice page to look at, but for the computer, it is not a script that can be executed or code that can be compiled, but a web page to be displayed. That web page has a button called Raw that sends you to the corresponding content on raw.githubusercontent.com.

To see the content of raw.githubusercontent.com/${user}/${repo}/${branch}/${path} in the usual github interface:

  1. you replace raw.githubusercontent.com with plain github.com
  2. AND you insert "blob" between the repo name and the branch name.

In this case, the user is "Homebrew", the repo is "install", the branch name is "master" (which is a very common branch name). You insert "blob" between "install" and "master", so

https://raw.githubusercontent.com/Homebrew/install/master/install

becomes

https://github.com/Homebrew/install/blob/master/install

This is the reverse of finding a file on Github and clicking the Raw link.

Law29
  • 637
  • 1
  • 10
  • 16
  • What does an argument to the URL mean, e.g. `https://raw.githubusercontent.com//master/filters/file.txt?_=215612` - what is the `?_=215612`'s purpose – simpleuser Mar 12 '19 at 18:18
  • The `?` is simply to separate the "path" from the "searchpart" (RFC 1738 section 3.3). The searchpart is here `_=215612`. The searchpart does not have to be a search, it is interpreted by the server. What that could mean in a raw file I do not know. My only idea was that it could start or stop the data at that point in the file, but a test shows no difference. In fact, even on a normal github.com page I see no evidence of interpretation of the searchpart by github. If you still want to know, ask a new question, here or maybe on a forum dedicated to github. – Law29 Mar 12 '19 at 19:24
  • 2
    It probably prevents client-side caching (because the content of files can change) – mincrmatt12 Mar 02 '20 at 19:12
  • Not quite correct, you forgot the `user`, which comes first after the `hostname`. Check [this](https://stackoverflow.com/a/56943840/1705829) answer to learn about the user – Timo Jun 30 '21 at 19:55
  • @Timo True, I was conflating User and Repo, which might have been confusing. Improved, thanks. – Law29 Jul 01 '21 at 07:02
12
raw.githubusercontent.com/username/repo-name/branch-name/path

Replace username with the username of the user that created the repo.

Replace repo-name with the name of the repo.

Replace branch-name with the name of the branch.

Replace path with the path to the file.

To reverse to go to GitHub.com:

GitHub.com/username/repo-name/directory-path/blob/branch-name/filename