How do I get the raw version of a gist from github

2019-02-01 16:03发布

问题:

I need to load a shell script from a raw gist but I can't find a way to get raw URL.

curl -L address-to-raw-gist.sh | bash

回答1:

And yet there is, look for the raw button (on the top-right of the source code).

The raw URL should look like this:

https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{commit_hash}/{file}

Note: it is possible to get the latest version by omitting the {commit_hash} part, as shown below:

https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{file}


回答2:

February 2014: the raw url just changed.
See "Gist raw file URI change":

The raw host for all Gist files is changing immediately.
This change was made to further isolate user content from trusted GitHub applications.

The new host is

 https://gist.githubusercontent.com. 

Existing URIs will redirect to the new host.

Before it was https://gist.github.com/<username>/<gist-id>/raw/...

Now it is https://gist.githubusercontent.com/<username>/<gist-id>/raw/...

For instance:

https://gist.githubusercontent.com/VonC/9184693/raw/30d74d258442c7c65512eafab474568dd706c430/testNewGist

KrisWebDev adds in the comments:

If you want the last version of a Gist document, just remove the <commit>/ from URL

https://gist.githubusercontent.com/VonC/9184693/raw/testNewGist



回答3:

Gitlab snippets provide short concise urls, are easy to create and goes well with the command line.

Sample example: Enable bash completion by patching /etc/bash.bashrc

sudo su -
(curl -s https://gitlab.com/snippets/21846/raw && echo) | patch -s /etc/bash.bashrc


标签: gist