Chris Dzombak

University of Michigan CS engineering student, Ann Arborite, photographer, cyclist, weather geek, music lover.
Mobile Developer at Nutshell.

Making a Private Gist Public

Gist is a really nice tool for sharing and storing snippets of code, notes, and any other text you want. It lets you create private or public Gists - basically, sets of text files.

Sadly, it's not easy to switch a Gist from private to public (or vice versa). You can do this with a little Git-fu, since each Gist is its own Git repo. Here's how to do it.

Copy the Private Clone URL from the Gist's page and clone the Gist to a temporary directory:

~ $ git clone git@gist.github.com:PRIVATEGIST.git gist-private-temp
~ $ cd git-private-temp

From the Gist Web interface, create a new public Gist. You will need to add some dummy text to a file in the Gist since you can't create a totally empty Gist. This file will be deleted in the next step, though.

Copy the Private Clone URL from this new repo. Add the public Gist as a remote in your cloned copy of the private Gist, and push to it. (You'll need to do a forced push since the public Gist has the dummy file in it.)

~/gist-private-temp/ $ git remote add public git@gist.github.com:PUBLICGIST.git
~/gist-private-temp/ $ git push -f public

Finally, to get the new Gist content to appear on your Gist home page, go to the Gist's page, edit it, and resave it (without making any changes).

I was thinking about making a script to do this, but my understanding is that the necessary Gist API methods are only available in the Github API v3, which is not yet stable; and I couldn't find any Github API libraries that support it yet.

Responses

blog comments powered by Disqus