133

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?

4
  • 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? Commented Aug 21, 2016 at 16:30
  • I can't find 'install' file in repository, that's i asked this quitstion Commented Aug 21, 2016 at 16:40
  • 4
    Please note that rawgit.com is not an alias for raw.githubusercontent.com. It is a third party service not affiliated to GitHub. Commented Oct 3, 2018 at 14:49
  • 6
    Also RawGit is at or near end-of-life; see rawgit.com Commented Dec 26, 2018 at 17:30

3 Answers 3

153

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.

Sign up to request clarification or add additional context in comments.

5 Comments

My assumption was that install script locates in main repository, thanks
What does "unprocessed versions of files" mean pls ?
@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.
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, 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.
61

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.

5 Comments

What does an argument to the URL mean, e.g. https://raw.githubusercontent.com/<repo>/master/filters/file.txt?_=215612 - what is the ?_=215612's purpose
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.
It probably prevents client-side caching (because the content of files can change)
Not quite correct, you forgot the user, which comes first after the hostname. Check this answer to learn about the user
@Timo True, I was conflating User and Repo, which might have been confusing. Improved, thanks.
15
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.