Five easy steps to embed a single file from a GitHub gist on Medium?

Akshay Chavan
3 min readJan 31, 2021

I always had a hard time to add a single file from a GitHub gist on Medium. Everywhere I found was to use the link to the gist and that adds all the files in the gist.

I used to make different gists for every file I needed to add to the article. That made managing the gists for an article, a nightmare.

That did not stop me from trying to find a way to embed a single file from the gist. I mean it doesn’t make sense that the Medium platform does not allow to embed a single file from the GitHub gist.

Finally, I was able to find this post on Stack Overflow, surprisingly from 8 years ago where someone asked “How do I embed a single file from a GitHub gist with the new gist interface? and there Mojtaba Hosseini explained it in great detail on how to accomplish it. Due credit to Mojtaba Hosseini.

You can go through the solution on Stack Overflow as well.

I decided to write this article and thought that writing this article on Medium will be the best way to help someone find a solution to the issue.

Here are the steps:

  1. Copy the link to the gist.
  2. Paste it in a notepad, this removes any hyperlinks on the text.
  3. Append the following to the link ?file=gistfile.ext, where gistfile.ext is the name of the file in the gist you want to add.
  4. Copy the text from the notepad.
  5. Paste it on Medium as paste as plain text.

The important point here is to append the gist URL with ?file=file1.py

Let's see what happens when you copy a link to a gist and append ?file=file1.py.

Failed gist insert

Did not work. There is more to it. Medium doesn’t really take a URL without a hyperlink. Therefore, you can’t really copy and paste the gist URL and then append ?file=file1.py to it.

Here’s how to do it.

Append and copy from notepad
Successfully inserted gist

Paste the URL in notepad and append ?file=file1.py to it. Copy the whole text and paste it in Medium.

Voilà it works.

Here are the 3 gists inserted from a single gist.

Its simple just a little tricky. Hope this helps you.

--

--