Managing gists on the command line

I do appreciate the convenience of saving general-purpose code snippets and example code to Github gists, but the UX is less than stellar for a platform aimed at programmers. A gist must be added either by a drag-and-drop operation of your file into the browser, or by copy-pasting the code into a text box (or, if you really feel like it, by making a POST request to the API). Once uploaded each gist - often a single file - is treated like a full-featured git repo.

All of this feels a bit clunky and bloated just for saving some snippets. Luckily though there is a third-party gist command-line tool which makes this process a whole lot easier.


On many Linux distributions (and on Macs) it can be installed trivially using the package manager. For instance on Ubuntu:

sudo apt-get install gist

This will then make available the gist-paste utility. Authentication is managed with a OAuth2 token, obtained once through a web login flow and then saved to ~/.gist, by doing:

gist-paste --login


Most commonly I create a new gist with:

gist-paste -d "Description of the gist" myfile.ext

This will print the URL to stdout, which should give you the GIST_ID. The -p flag can be used to make it a secret gist instead.

To update the same gist:

gist-paste -u GIST_ID myfile.ext


Should you want to use one of your previously uploaded gists, list them to find the GIST_ID - perhaps grep’ed by words in the description to find the one you’re looking for:

gist-paste -l

To then download and use one specific gist, read it to stdout and save to a file. If the gist comprises of multiple files, the filename should be specified as well.

gist-paste -r GIST_ID > myfile.ext

And that’s it really! Have a look at the man for some more options, in particular with regard to automatically putting the URL on the clipboard.