How to add an image to a GitHub gist


Did you know you can upload images (and other static files) to a gist simply because it’s a Git repository?

Instructions

First you need to make sure you’re logged in to your GitHub account.

  1. Create or find a gist that you own.
  2. Clone your gist (replace <hash> with your gist’s hash):

    # with ssh
    git clone git@gist.github.com:<hash>.git mygist
    
    # or with https
    git clone https://gist.github.com/<hash>.git mygist
    
  3. Change to your gist’s directory:

    cd mygist
    
  4. Add and commit the image:

    git add image.jpg
    git commit -m "Add image to gist"
    
  5. Update remote:

    git push origin master
    

And voilà you can view the image in your gist:

open https://gist.github.com/<username>/<hash>

If you inspect the Raw file, you’ll get something like the following:

https://gist.githubusercontent.com/<username>/<gist-sha>/raw/<commit-sha>/image.jpg

One disadvantage of gist is it doesn’t support directories. This means all files live in the root folder of the repository.

Example

See gist:



Please support this site and join our Discord!