Posting Jupyter Notebooks On Medium
Medium allows you to easily embed GitHub gists into an article and GitHub renders Jupyter Notebooks from gists. So all you have to do is post your notebook’s contents into a gist and embed it. Here’s an example:
Now, if you already have a git repo that you’re using for the notebook you can’t just embed it from there. The easiest way to do that is to add a gist as a remote. There’s one main catch though; your repo must not have any folders.
Here’s how to add a gist as a remote:
- Go to gist.github.com and create a new gist
- You can call it whatever you like, but make sure to add a file otherwise you won’t be able to create the gist
- On the gist’s page you should be able to find a url to clone the gist, copy that
- If you use GitKraken or some other tool, you can add the remote that way, otherwise, open terminal, go to your git repo and then type
git remote add gist <url-you-copied>
(You can replace “gist” with another name, but be sure to use that name in the next step) - Then in terminal, type
git push gist master --force
- Voila! You should have a gist that has all the code from your repo. Don’t forget to push to both origin and gist when you update your notebook!
Note: I’m still having an issue with embedding just one file on medium instead of all files of a gist. Will update once I figure out a way around that.