Skip to content

Instantly share code, notes, and snippets.

@kennypete
Last active April 24, 2023 20:39
Show Gist options
  • Save kennypete/9d4693e882f4ad4d75990e1a7576ce6f to your computer and use it in GitHub Desktop.
Save kennypete/9d4693e882f4ad4d75990e1a7576ce6f to your computer and use it in GitHub Desktop.
Creating an images repository gist

Creating an images repository gist

The problem

When creating a GitHub repository README[1] you may want to have .jpg files, or even animated .gif files[2], to demonstrate things. Those can be added to the repository itself, but then everyone who clones or downloads the repository gets those files too, which may be many times larger than the actual code, so may be unnecessary bloat.

A solution

An images gist is created easily. It enables you to add images to your repositories' READMEs by adding full links to your gist’s images. The approach outlined is not one I have seen used, though it is effective in keeping the size of your repository(ies) slimmer. So, I thought it was worthwhile outlining it for others (and as a record for me to come back to too).

1. Create a new gist

Your gist should have one .adoc (or .md, if you prefer). You will want it to appear as the “top” page (i.e., not have one of your images appear first) so the file name needs to sort alphabetically before any of the images’ file names. A good way to do that is to type a _ (LOW LINE, U+005F) at the start of the .adoc file name. In this gist, I created the file _How_To_Images_Gist.adoc. The content of the .adoc is not too important other than the heading, i.e., name it so that it is logically related to your repository(ies), and is easily identified when displayed in your gist’s home page.

You will probably want to make your gist a secret gist if all it will be doing is storing images for your repository(ies). Click the green button to Create secret gist.

💡
This does not impact accessing the images because secret gists are not actually very secret ― if someone knows the URI to your gist, they have access to view it.

2. Clone your gist repository, add and commit your images, and push it

  1. Get your gist’s “Clone via HTTPS” link:

    creating_an_images_gist_01
    Figure 1. ✓ Clone via HTTPS

     

  2. Using your git command line (or GUI) of choice, clone your gist. Using Git Bash on Windows, in my case it is:

    git clone https://gist.github.com/9d4693e882f4ad4d75990e1a7576ce6f.git
  3. Now copy whatever images you want added to the same directory as the .adoc file. That’s because gists cannot have any subdirectories, so these all need to be at the “root”.

  4. Once copied, use git add * and then git commit -m "Adding images" to commit the image files.

  5. Finally, git push to GitHub (changing the {personal-access-token} to yours[3] and using your gist repo’s code, which you got from the "Clone via HTTPS" link). It should be like this: git push https://{personal-access-token}@gist.github.com/9d4693e882f4ad4d75990e1a7576ce6f.git, noting the “@”.

This should update your repository, with the images appearing below the .adoc file as individual files in your gist. Here’s the procedure above illustrated:

creating_an_images_gist_02
Figure 2. Copy images, git add, git commit, git push

3. Using your gist’s images in your repository

Now that the images are in your gist, they can be used wherever you like, including your GitHub repositories. It is simply a matter of right clicking the image, and copying the image’s link, like this:

creating_an_images_gist_03.jpg
Figure 3. Copying the link to an image

Conclusion

This gist repository itself uses the images within it, but the principle is the same for any repository. So, the images in this gist could be used in any repository. For example, the first image used in this file is image::https://gist.github.com/kennypete/9d4693e882f4ad4d75990e1a7576ce6f/raw/9efe08af27327ba19b9df4977843212db4ebc902/creating_an_images_gist_01.jpg[creating_an_images_gist_01].[4]


1. Asciidoc (README.adoc) being my preference, but markdown (README.md) or any of the other allowed formats too.
2. These work when the README is loaded, though be aware they will not display in "Preview" if you edit a README directly in Github.
3. If you do not have a personal access token that includes rights to update gists, create one now: GitHub docs on how to do that.
4. In markdown it would be similar, ![creating_an_images_gist_01](https://gist.github.com/kennypete/9d4693e882f4ad4d75990e1a7576ce6f/raw/9efe08af27327ba19b9df4977843212db4ebc902/creating_an_images_gist_01.jpg), I think.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment