GitGitHub Gists

GitHub Gists

A gist is a tiny, single-purpose GitHub repository for sharing snippets — one or a handful of files, no issues, no PRs, no settings tab. Gists live on gist.github.com and each one is itself a real Git repository you can clone and push to. They are GitHub's answer to pastebin, with the added bonus of version history.

What gists actually are
  • A Git repository, just like any other — with a SHA, history, and a git clone URL.

  • Limited to a single "tree" of files (no subdirectories).

  • No collaborators, no issues, no PRs, no branches in the GitHub UI.

  • Anyone with the URL can comment, fork, or star.

  • Renders Markdown, code, GeoJSON, CSV (as a sortable table), and IPython notebooks automatically.

Public vs secret — the misunderstanding
Warning
A "secret" gist is **unlisted**, not private. Anyone with the URL can read it, and the URL is just a random-looking string that could be guessed or shared. Never put credentials, customer data, or anything sensitive in a secret gist. If it must be private, use a private repository instead.

Visibility

Listed in search?

Shows on profile?

URL guessable?

Use for

Public

Yes

Yes

Yes

Snippets you want others to find

Secret (unlisted)

No

No

Practically no

Code shared in a ticket or chat — NOT secrets

Creating a gist
  • Go to gist.github.com.

  • Add a description (optional, but helpful in your own list later).

  • Type a filename including the extension — query.sql, script.py, notes.md. The extension drives syntax highlighting.

  • Paste the content.

  • Optionally click Add file to attach more.

  • Pick Create secret gist or Create public gist.

Create from the CLI

Bash
# Single file
gh gist create script.py

# Multiple files at once
gh gist create script.py README.md config.yml

# Public (default is secret)
gh gist create --public notes.md

# From stdin
cat script.py | gh gist create --filename script.py
Editing and history

Every gist is a real Git repo — clone it

Bash
# The gist URL has a hash like 9b7d4a1234abcd...
git clone https://gist.github.com/9b7d4a1234abcd.git my-gist
cd my-gist

# Edit, commit, push — full Git history, just like any repo
git commit -am "Tweak the regex"
git push

Every commit you push to the gist shows up in the Revisions tab on the web UI, with diffs. Gists have full history.

Embedding gists in blog posts

Each gist provides an <script> embed tag (click the Embed button on the gist page). Drop it into HTML and the gist renders inline, syntax-highlighted, with a link back to the original.

The embed snippet

Text
<script src="https://gist.github.com/jsmith/9b7d4a1234abcd.js"></script>

<!-- Embed only one file from a multi-file gist -->
<script src="https://gist.github.com/jsmith/9b7d4a1234abcd.js?file=script.py"></script>

Note: in static-site generators that use Markdown, you can usually just include the raw <script> tag and the renderer will let it through.

Useful gist tricks
  • Star a gist to bookmark it on your profile's Stars tab.

  • Fork a gist to keep your own copy with edits — preserves a link back to the original.

  • Comment on a gist — useful for asking the author a quick question without opening an issue elsewhere.

  • raw.githubusercontent.com-style URLsgist.githubusercontent.com/jsmith/<id>/raw/script.py returns the plain file, useful for curl | sh style installers.

  • Multi-file gist as a config dotfiles dump — historically common; today people use dotfiles repos instead.

When to use a gist vs a full repo

Use a gist when

Use a full repo when

You have 1-5 files of throwaway code

You have a directory tree

Sharing a snippet in a ticket or chat

Project has issues, PRs, or releases

Embedding code in a blog post

Code needs CI, tests, or workflows

Replacing pastebin for ephemeral sharing

You want collaborators or branches

Demoing a single function or query

You will iterate on it long-term

Limitations to be aware of
  • No directory structure — every file is at the root.

  • No collaborators — you cannot give someone push access; they have to fork and submit a new gist.

  • No issues, no PRs, no Discussions.

  • No Actions, no CI, no webhooks (gists do have a webhook of sorts, but no workflow support).

  • No releases or tags in the UI (the Git repo accepts tags, the UI just ignores them).

  • Cannot make a public gist private — you must delete and re-create.

Gist vs the competition

Tool

Persistence

Versioning

Best for

GitHub Gist

Forever (until deleted)

Full Git history

Code snippets, paste-bin replacement

pastebin.com

Optional expiry

No history

Plain text, throwaway sharing

hastebin / 0bin

Short-lived

No history

One-time shares

CodePen

Forever

Snapshots

HTML/CSS/JS demos with live preview

JSFiddle

Forever

Revisions

Quick JS experiments with a runner

CodeSandbox / StackBlitz

Forever

Git-backed

Full Node/React projects in browser

Listing and managing your gists

From the gh CLI

Bash
gh gist list                       # your recent gists
gh gist list --public --limit 50   # public ones only
gh gist view <id>                  # show contents
gh gist edit <id>                  # open in $EDITOR, save, push
gh gist delete <id>                # permanent

# Clone every gist you have for backup
gh gist list --limit 1000 | awk '{print $1}' | \
  xargs -I{} git clone https://gist.github.com/{}.git
Common gotchas
  • Pasting a long secret into a "secret" gist and assuming nobody can see it. They can if they get the URL.

  • Linking to a gist in a Slack message that auto-expands — the gist content lands in Slack search forever.

  • Forgetting that deleting a gist doesn't delete forks. If someone forked it, the code is still out there.

  • Using a gist for something that grows into a project — move to a repo before the tail wags the dog.

Gists are Git repos in disguise
Anything you can do with a regular Git repo, you can do with a gist: clone, branch (locally), tag, push, pull. The GitHub UI just hides most of that. If you outgrow what the UI offers, you can always `git clone` the gist and treat it as a normal repo.
Tip
Use `gh gist create` from the terminal to share command output or log snippets: `journalctl -u nginx | tail -200 | gh gist create --filename nginx.log`. The CLI prints the URL ready to paste into chat.