Managing Gists Locally

Danny Quah
2 min readMay 9, 2020

--

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

Using the feature that a git repo on the local filesystem can be associated with multiple remotes on GitHub, it is possible also, alternatively and optionally, to get fancy by saving 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.

Originally published at http://github.com.

--

--

Danny Quah
Danny Quah

Written by Danny Quah

Danny Quah is Dean and Li Ka Shing Professor in Economics at the Lee Kuan Yew School of Public Policy, NUS.

No responses yet