41

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
2

5 Answers 5

85

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}
Sign up to request clarification or add additional context in comments.

7 Comments

While that link does get the raw , it is hard coded to that specific commit.
is there a possibility to get the latest raw version? If you omit the commit hash, it doesn't work neither...
@nerdoc Just omit the commit hash in the URL. e.g., gist.github.com/aymericbeaumet/940d6360efe5a4618302c291c7b2d051/… would be accessed in a raw version as gist.githubusercontent.com/aymericbeaumet/…
I thought that too, as it seems obvious. but it did not work. Tried, but did not work for me. Either there was a small (cache?) delay? I moved to GitLab snippets, there it works as expected.
AAAARRRGGGHHH! gist.githubusercontent.com/nerdoc/… - I have to omit the commit hash, but provide the filename afterwords. So easy, but drove me nuts. Thanks.
|
31

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 Comments

@KrisWebDev good point. I have included in the answer for more visibility, along with an example.
The raw host for all Gist files is changing immediately. But I found it not immediately
A better way would be also to pay attention to the API: api.github.com/gists/9184693 You can get from there the raw_url and use that. This answere is correct, no doubt, but the API will (never) be outdated, it could be possible they change it again like in FEB 2014.
5

One can simply use the github api.

https://api.github.com/gists/$GIST_ID

Reference: https://miguelpiedrafita.com/github-gists

1 Comment

This API returns JSON data, from which you can get the raw URL as follows: url = json_data["files"][filename]["raw_url"] where filename is the name of a specific file within the gist.
2

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

Comments

0

Adding one note to @aymericbeaumet's answer ... It seems possible to also omit the file part in url if there's only one file in the gist. For example:

curl -s https://gist.githubusercontent.com/karpathy/d4dee566867f8291f086/raw

prints

"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np

# data I/O
...

as of 2025-02-28.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.