Need help with gist?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

3.7K Stars 341 Forks MIT License 512 Commits 54 Opened issues


Potentially the best command line gister.

Services available


Need anything else?

Contributors list

gist(1) -- upload code to


The gist gem provides a

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

‌For FreeBSD, gist lives in ports

pkg install gist

<200c>For Ubuntu/Debian

apt install gist

Note: Debian renames the binary to

to avoid a name conflict.


‌To upload the contents of

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

gist -f test.rb 

‌Alternatively, you can just paste from the clipboard:

gist -P


to make the gist private:
gist -p a.rb


to add a description:
gist -d "Random rbx bug" a.rb

‌You can update existing gists with

gist -u 42f2c239d2eb57299408 test.txt

‌If you'd like to copy the resulting URL to your clipboard, use

gist -c 

‌If you'd like to copy the resulting embeddable URL to your clipboard, use

gist -e 

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

gist -o 

‌To list (public gists or all gists for authed user) gists for user

gist -l : all gists for authed user
gist -l defunkt : list defunkt's public gists

To read a gist and print it to STDOUT

gist -r GIST_ID
gist -r 374130


gist --help
for more detail.


Before you use

for the first time you will need to log in. There are two supported login flows:
  1. The Github device-code Oauth flow. This is the default for authenticating to, and can be enabled for Github Enterprise by creating an Oauth app, and exporting the environment variable
    with the client id of the Oauth app.
  2. The (deprecated) username and password token exchange flow. This is the default for GitHub Enterprise, and can be used to log into by exporting the environment variable

The device-code flow

This flow allows you to obtain a token by logging into GitHub in the browser and typing a verification code. This is the preferred mechanism.

gist --login
Requesting login parameters...
Please sign in at
  and enter code: XXXX-XXXX

The returned access_token is stored in

and used for all future gisting. If you need to you can revoke access from

The username-password flow

This flow asks for your GitHub username and password (and 2FA code), and exchanges them for a token with the "gist" permission (your username and password are not stored). This mechanism is deprecated by GitHub, but may still work with GitHub Enterprise.

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

This token is stored in

and used for all future gisting. If you need to you can revoke it from, or just delete the file.

Password-less login

If you have a complicated authorization requirement you can manually create a token file by pasting a GitHub token with

scope (and maybe the
for GitHub Enterprise) into a file called
. You can create one from

This file should contain only the token (~40 hex characters), and to make it easier to edit, can optionally have a final newline (


For example, one way to create this file would be to run:

(umask 0077 && echo MY_SECRET_TOKEN > ~/.gist)


ensures that the file is only accessible from your user account.

GitHub Enterprise

If you'd like

to use your locally installed GitHub Enterprise, you need to export the
environment variable (usually done in your
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

Your token for GitHub Enterprise will be stored in

for the GITHUB_URL example above) instead of

If you have multiple servers or use Enterprise and public GitHub often, you can work around this by creating scripts that set the env var and then run

. Keep in mind that to use the public GitHub you must unset the env var. Just setting it to the public URL will not work. Use

Token file format

If you cannot use passwords, as most Enterprise installations do, you can generate the token via the web interface and then simply save the string in the correct file. Avoid line breaks or you might see:

$ gist -l
Error: Bad credentials


‌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
  • :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).
  • :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

scope and may also require the

‌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

, where it can later be read by


‌If you'd like

to be the default when you use the gist executable, add an alias to your
(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

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.