Create gists from Command Line

By  on  

One of the best ways to gain contributors for your open source project is by providing a rough patch for the contributor to start from.  One of the best ways to ask for help is by providing what you have so far and letting a mentor look it over and provide suggestions.  In both cases, you'll need to put the code somewhere accessible by all parties and, since GitHub has taken over the code hosting world, what better platform to do it on?

Since pull requests make a lot of noise and the code you want to share isn't always merge material, the next best way is providing a GitHub gist.  Gists are easy to create manually but I wanted an automated method for creating gists, so I've turned to pretty-diff's gist-diff, a single command that creates a GitHub gist with git diff contents.

Installation and Configuration

Start by installing pretty-diff:

npm install -g pretty-diff

The next step is ensuring your global git config knows your GitHub username:

git config --global github.user "MyGitHubUsername"

The last step is going to GitHub and creating a Personal Access Token (don't forget to check the "Create gist" checkbox) for the functionality pretty-diff provides.  Once you've created the token, execute the following:

git config --global gist-diff.token "######################"

Now we're ready to use gist-diff!

Creating a Gist

Once you've create the changes you'd like to share, run gist-diff to send your changes to GitHub:

# just execute the command!
gist-diff

gist-diff creates a gist and then opens your browser to the URL of the gist.

I wish I had known about pretty-diff sooner, and from this point forward, it's going to be one of the first utilities I install on every new work computer.  Sharing code is one of the luxuries of the modern open source landscapes and the ability to create a gist of current changes with one command is a huge time saver.

Recent Features

  • By
    Create a CSS Cube

    CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals.  Add animation and you've got something really neat.  Unfortunately each CSS cube tutorial I've read is a bit...

  • By
    Convert XML to JSON with JavaScript

    If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium.  The experience has been great:  using JavaScript to create easy to write, easy to test, native mobile apps has been fun.  My...

Incredible Demos

  • By
    CSS Sprites

    The idea of CSS sprites is pretty genius. For those of you who don't know the idea of a sprite, a sprite is basically multiple graphics compiled into one image. The advantages of using sprites are: Fewer images for the browser to download, which means...

  • By
    Create Custom Events in MooTools 1.2

    Javascript has a number of native events like "mouseover," "mouseout", "click", and so on. What if you want to create your own events though? Creating events using MooTools is as easy as it gets. The MooTools JavaScript What's great about creating custom events in MooTools is...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!