Skip to content

Instantly share code, notes, and snippets.

@DannyQuah
Last active April 15, 2024 20:08
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save DannyQuah/5f43f9b75970bc4e357e42c7c9214b5d to your computer and use it in GitHub Desktop.
Save DannyQuah/5f43f9b75970bc4e357e42c7c9214b5d to your computer and use it in GitHub Desktop.
Managing Gists Locally

Managing Gists Locally

by Danny Quah, May 2020 (revised Jan 2022)

Through the Embed instruction or plugin, Gist snippets on GitHub can conveniently provide posts on Medium, WordPress, and elsewhere supplementary information (lines of code, images, Markdown-created tables, and so on). But while Gist snippets on GitHub can be managed directly via browser or through something like Gisto, a user might also wish to manipulate them offline. This last is for many of the same reasons that a user seeks to clone a git repo to their local filesystem, modify it locally, and then only subsequently push changes back up to GitHub.

Here's how to do this:

Create the gist on GitHub and then clone it to your local filesystem:

$ git clone https://gist.github.com/DannyQuah/5f43f9b75970bc4e357e42c7c9214b5d

Locally, rename that folder however you wish (or just leave it as that long string):

$ mv -i 5f43f9b75970bc4e357e42c7c9214b5d YYYY.MM-Author-Subject

Work on the file inside YYYY.MM-Author-Subject/; and then, whenever ready, as usual do:

$ # changes ...
$ git commit -m "The new changes"
$ git push

Putting the Gist on GitHub additionally

You can leave this as above. But you can also get fancier.

Using the feature that a git repo on the local filesystem can be associated with multiple remotes on GitHub, it is possible, alternatively and optionally, to save both a gist and a git repo on GitHub. Doing so follows Ishu3101.

(In the sequel, anything that begins my should be named however the user prefers.)

After the steps, above also create on GitHub a new git repo myGistProject; then from inside YYYY.MM-Author-Subject/ add that new GitHub repo as a remote, labelling it myGitHub for git use, i.e.,

$ git remote add myGithub https://github.com/DannyQuah/myGistProject

Push to the new repository on GitHub

$ git push myGithub main

Keep things parallel by renaming the remote of the Gist snippet: origin is where this had come from, so now instead call it myGist

$ git remote rename origin myGist

Now each time push either to myGithub or myGist (or both, obviously):

$ # changes
$ git commit -m "The new changes"
$ git push myGithub main # to github
$ git push myGist master # to gist

Prosper.

(As far as I have been able to tell gist.github.com continues to use master as the primary branch while since Oct 2020 github.com itself has switched to main.)

References:

@idiotandrobot
Copy link

idiotandrobot commented Nov 21, 2022

Or you can change the name of the target folder during the clone:-

$ git clone https://gist.github.com/DannyQuah/5f43f9b75970bc4e357e42c7c9214b5d 2020.05-D.Quah-Managing-Gists-Locally.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment