Managing Gists Locally

Managing Gists Locally

by Danny Quah, May 2020

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 localGistFolder

Work on the file inside localGistFolder/; 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 localGistFolder/ 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 master

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 master # to github
$ git push myGist master   # to gist

Prosper.

References:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: