Author: DeppWang, original address

Sometimes we need to download a file from someone else’s GitHub repository, but when we have to clone the entire project, we need a way to download a file directly.

A single download can be implemented by simply changing the GitHub file URL.

Suppose the original URL of the GitHub file is:

https://github.com/DeppWang/Java-Books/blob/master/docs/Algorithms, 4th Edition.pdf
Copy the code

Change it to:

https://raw.githubusercontent.com/DeppWang/Java-Books/master/docs/Algorithms, 4th Edition.pdf
Copy the code

That is, will be replaced with raw.githubusercontent.com, github.com and remove/blob.

You can download the Algorithms, 4th Edition. PDF file directly

The principle of

Raw.githubusercontent.com return file stored in the making of raw content (the original), so they can be easily downloaded to a computer. Can right click on the web page to see the way the source file validation file contains URL raw.githubusercontent.com.

Other examples: Install Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Copy the code

reference

  • What do raw.githubusercontent.com URLs represent?

How to let others directly read their own Github PDF file online

If the PDF file is large, it cannot be previewed directly on GitHub. You can do this with GitHub’s GitHub Pages.

GitHub Pages converts a repo into a web site that can be viewed directly online from the PDF file inside the repo.

The operation steps are as follows:

  1. Create a file namedUSERNAME.github.ioRepo, the equivalent of your personal website. Can be accessedhttps://USERNAME.github.iotest

  1. Go back to the project where you saved the file, repo, inSettingsGitHub PagesSelect a branch from,This operation takes the REPO ashttp://USERNAME.github.ioA file in.

  1. Project repo’s intro.pdf is available athttps://USERNAME.github.ioThe link:
http://USERNAME.github.io/REPONAME/path/Intro.pdf
Copy the code
  1. Example: Project Java-Books [Algorithms, 4th edition.pdf](github.com/DeppWang/Ja… PDF) at deppwang.github. IO / :
https://deppwang.github.io/Java-Books/docs/Algorithms, 4th Edition.pdf
Copy the code

reference

  • Can I trick GitHub into displaying the PDF in the browser instead of downloading it?
  • GitHub Pages

Usage scenarios

  • Github.com/DeppWang/Ja…

This article was automatically published by ArtiPub