gist rspec ruby Rubygems

Potentially the best command line gister.

gist(1) – upload code to


The gist gem provides a gist command that you can use from your terminal to upload content to


‌If you have ruby installed:

gem install gist

‌If you’re using Bundler:

source :rubygems
gem 'gist'

‌For OS X, gist lives in Homebrew

brew install gist


‌To upload the contents of a.rb just:

gist a.rb

‌Upload multiple files:

gist a b c
gist *.rb

‌By default it reads from STDIN, and you can set a filename with -f.

gist -f test.rb <a.rb

‌Alternatively, you can just paste from the clipboard:

gist -P

‌Use -p to make the gist private:

gist -p a.rb

‌Use -d to add a description:

gist -d "Random rbx bug" a.rb

‌You can update existing gists with -u:

gist lib/gist.rb bin/gist -u 42f2c239d2eb57299408

‌If you’d like to copy the resulting URL to your clipboard, use -c.

gist -c <a.rb

‌If you’d like to copy the resulting embeddable URL to your clipboard, use -e.

gist -e <a.rb

‌And you can just ask gist to open a browser window directly with -o.

gist -o <a.rb

‌See gist --help for more detail.


If you want to associate your gists with your GitHub account, you need to login with gist. It doesn’t store your username and password, it just uses them to get an OAuth2 token (with the “gist” permission).

gist --login
Obtaining OAuth2 access_token from github.
GitHub username: ConradIrwin
GitHub password:
2-factor auth code:

You can read the 2-factor auth code from an sms or the authentification app, depending on how you set your account up.

Note: 2-factor authentication just appeared recently, so if you run into errors, update the gist gem.

gem update gist

This token is stored in ~/.gist and used for all future gisting. If you need to you can revoke it from, or just delete the file. If you need to store tokens for both and a Github Enterprise instance you can save your Github Enterprise token in ~/ where “” is the URL for your Github Enterprise instance.

‌After you’ve done this, you can still upload gists anonymously with -a.

gist -a a.rb


‌You can also use Gist as a library from inside your ruby code:

Gist.gist(" => 'awesome').code")

If you need more advanced features you can also pass:

  • :access_token to authenticate using OAuth2 (default is `“~/.gist”)).
  • :filename to change the syntax highlighting (default is a.rb).
  • :public if you want your gist to have a guessable url.
  • :description to add a description to your gist.
  • :update to update an existing gist (can be a URL or an id).
  • :anonymous to submit an anonymous gist (default is false).
  • :copy to copy the resulting URL to the clipboard (default is false).
  • :open to open the resulting URL in a browser (default is false).

NOTE: The access_token must have the “gist” scope.

‌If you want to upload multiple files in the same gist, you can:

Gist.multi_gist("a.rb" => "", "" => "")

‌If you’d rather use gist’s builtin access_token, then you can force the user to obtain one by calling:


‌This will take them through the process of obtaining an OAuth2 token, and storing it in ~/.gist, where it can later be read by Gist.gist

GitHub enterprise

‌If you’d like gist to use your locally installed GitHub Enterprise, you need to export the GITHUB_URL environment variable in your ~/.bashrc.

export GITHUB_URL=

‌Once you’ve done this and restarted your terminal (or run source ~/.bashrc), gist will automatically use github enterprise instead of the public


‌If you’d like -o or -c to be the default when you use the gist executable, add an alias to your ~/.bashrc (or equivalent). For example:

alias gist='gist -c'

‌If you’d prefer gist to open a different browser, then you can export the BROWSER environment variable:

export BROWSER=google-chrome

If clipboard or browser integration don’t work on your platform, please file a bug or (more ideally) a pull request.

If you need to use an HTTP proxy to access the internet, export the HTTP_PROXY or http_proxy environment variable and gist will use it.


Thanks to @defunkt and @indirect for writing and maintaining versions 1 through 3. Thanks to @rking and @ConradIrwin for maintaining version 4.

Licensed under the MIT license. Bug-reports, and pull requests are welcome.

Related Repositories



vimscript for gist ...



Ultra powered gist embedding for your website ...



Yet another Emacs paste mode, this one for Gist. ...



Gist command line interface ...



A tool to make it easy to share snippets of code between projects and developers via ...

Top Contributors

ConradIrwin defunkt indirect rking pix kui Fleurer mattn akahn Aupajo dlo headius ermaker rmanalan cliffrowley QuinnyPig metakermit jrk locks boucher zph adamv ainformatico alistra brtsz davedash evmar EvanPurkhiser jacknagel jmelis


-   v4.2.1 zip tar
-   v4.1.3 zip tar
-   v4.1.2 zip tar
-   v4.1.1 zip tar
-   v4.1.0 zip tar
-   v4.0.3 zip tar
-   v4.0.2 zip tar
-   v4.0.1 zip tar
-   v4.0.0 zip tar
-   v3.1.0 zip tar
-   v3.0.1 zip tar
-   v3.0.0 zip tar
-   v2.0.3 zip tar
-   v2.0.2 zip tar
-   v2.0.1 zip tar
-   v2.0.0 zip tar
-   v1.4.1 zip tar
-   v1.4.0 zip tar
-   v1.3.0 zip tar
-   v1.2.1 zip tar
-   v1.2.0 zip tar
-   v1.1.1 zip tar
-   v1.1.0 zip tar
-   v1.0.3 zip tar
-   v1.0.2 zip tar
-   v1.0.1 zip tar
-   v1.0.0 zip tar
-   v0.7.5 zip tar