8

I have a URL to a gist, raw version but it won't always update. Say I get the raw link

https://gist.githubusercontent.com/username/27610b513177a762470ac95160c050fd/raw/f567a5ade06c9b8e7c101fe62fa3a4cac07e5bd7/test%2520gist

But I change the contents of that gist, the URL will change, the first link WONT include the changes.

https://gist.githubusercontent.com/username/27610b513177a762470ac95160c050fd/raw/60e3b421faa7e4e9ea6cd27e4a6ffd4809d3d40e/test%2520gist

How do I make 1 PERMANENT link that will forever include all the changes, not just the revision for that link?

I've tried with the ID, and just the id/raw but the ID isn't even a number like other people say, its more like a hash, can anyone help here?

UPDATE:

I've tried [the suggested answer], but it still leads to the last revision, does it have a delay in updating?

xpt
  • 20,363
  • 37
  • 127
  • 216
zhorachu
  • 91
  • 1
  • 3
  • 1
    Possible duplicate of [How do I get the raw version of a gist from github?](https://stackoverflow.com/questions/16589511/how-do-i-get-the-raw-version-of-a-gist-from-github) – brasofilo Nov 13 '17 at 15:46
  • Does this answer your question? [Is there a permalink to the latest version of gist files?](https://stackoverflow.com/questions/46073096/is-there-a-permalink-to-the-latest-version-of-gist-files) – Mohammad Ayoub Khan Mar 24 '21 at 00:48

3 Answers3

9

the ID isn't even a number like other people say, its more like a hash

Yes, a gist is a git repo

As explained here by Mark Engel:

Imagine you want to host a json configuration file somewhere. You also don’t want to host it yourself, but would prefer to rely on a stable provider.

You can use gist.github.com for this job.

For example this gist. You can see that there are 2 revisions.

If you click on raw you get the current version

In each version you see two hashes.

  • One hash is equal in both hashes. This is the hash of the gist
  • The other hash is the hash of the commit.

If you remove the last one the raw file always points to the latest revision

https://gist.githubusercontent.com/mren/17da9837f691acd2e8ae/raw/config.json

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I've tried this, it still leads to the last revision, does it have a delay in updating? I'm confused. – zhorachu Nov 02 '17 at 23:46
  • @zhorachuI thought you wanted a permanent link to the latest revision: https://gist.githubusercontent.com/mren/17da9837f691acd2e8ae/raw/config.json is one permanent URL that will always "include all the changes" – VonC Nov 03 '17 at 06:58
  • @zhorachu OK. I wasn't ware of that delay. – VonC Nov 03 '17 at 16:48
4

Reviving this link to clarify the confusion.

Yes, VonC's answer is right,

If you remove the last one the raw file always points to the latest revision

and,

permanent URL ... will always "include all the changes"

However, it may do INDEED take some time to update.

Today, I was using bit.ly to shorten my permanent URL, but found it always points to the last/initial version that I set the short URL. So I have to give it up and try different URL shortening services. Only after trying two or three more did I realize that the problem is not at URL shortening service side but the gist permanent URL side -- confirmed by visiting the gist permanent URL directly, and --

it does take more than two or three minutes to update some times today, when I keep changing it to see what's wrong. But it does eventually change to the latest version as well. Confirmed by revisiting my bit.ly shortened URL as well.

xpt
  • 20,363
  • 37
  • 127
  • 216
1

For those that may need a programmatic solution (e.g. dynamically editing/updating a gist during web scraping)...

As of May 2021, a workaround to avoid the delay associated with the cache of the last commit is using the URL associated with the "Raw" button of the UI, shown below.

RawButton

  • The URL of interest will be of the format: https://gist.github.com/{user}/{gist_hash}/raw/{commit_hash}/{filename}

  • If you parse the DOM for the link associated with this button, you can bypass the 2-3 minute delay normally associated with using the link of the format: https://gist.github.com/{user}/{gist_hash}/raw

  • Sample code to retrieve this link in Python would look something like the following:

Script to retrieve raw gist link (bypasses cache-related wait time)

# Python 3.9.1
import requests
from bs4 import BeautifulSoup

repo_url = f'https://gist.githubusercontent.com/{user}/{gist_hash}'
html = requests.get(repo_url).text
soup = BeautifulSoup(html, 'html.parser')
button = soup.find_all('div', class_='file-actions flex-order-2 pt-0') # Finds "Raw" button
raw_url = f"https://gist.github.com/{button[0].contents[1].attrs['href'][1:]}"
> print(raw_url)

'https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{commit_hash}/{filename}'
Justin Dehorty
  • 1,383
  • 1
  • 15
  • 26