Pastebins

GitHub Gist

GitHub's snippet sharing service. Every gist is a Git repository with revision history, and gists can be embedded in web pages. Needs a GitHub account to create.

  • Git versioning
  • Embeds
  • Secret gists
  • API
  • CLI

About GitHub Gist

GitHub Gist is the snippet and paste service run by GitHub. It is aimed at sharing code, configuration files, notes and small scripts, and describes itself as a way to "instantly share code, notes, and snippets".

Each gist can contain one or more files, and every gist is a full Git repository. That means you can clone it, fork it, see its complete revision history with diffs, and download it as a ZIP file. Gists can also be embedded in blog posts and other web pages with a single script tag.

Gists are either public or secret. Public gists appear in the Discover page and in search. Secret gists are hidden from both but are not private: anyone with the link can read them.

How to create a paste

  1. Sign in to GitHub and go to gist.github.com.
  2. Add an optional description, then enter a filename with an extension (used to choose syntax highlighting) and the file contents. Use Add file for more files.
  3. Choose Create secret gist or, from the drop-down, Create public gist.

With the GitHub CLI installed and authenticated, you can create a gist from the terminal:

gh gist create notes.txt
gh gist create --public script.py

Things to know

  • Privacy: secret gists are unlisted rather than private. Do not use either type for credentials or confidential data.
  • Visibility changes: a secret gist can be made public, but not the other way round.
  • Embedding: use the embed code shown on a gist page. Add ?file=FILENAME to the embed URL to embed a single file.
  • API limits: the REST API returns up to 1 MB of content per file and up to 300 files per gist. Larger content is available through the raw URL or by cloning.
  • Account: gists are tied to your GitHub account and are subject to GitHub's terms and acceptable use policies.

Frequently asked questions

Are secret gists private?

No. A secret gist is not listed in Discover or search results, but anyone who has the URL can view it. GitHub recommends a private repository for code that must stay hidden.

Do I need a GitHub account to use Gist?

You can read public gists without signing in, but you must be signed in to a GitHub account to create a gist.

Can I turn a public gist into a secret one?

No. A secret gist can be made public by editing it, but a public gist cannot be converted back to secret.

Sources

  1. docs.github.com/en/get-started/writing-on-github/editing-and-sharing-content-with-gists/creating-gists
  2. docs.github.com/en/rest/gists/gists
  3. cli.github.com/manual/gh_gist_create
  4. gist.github.com