>_ ghcli.com
ghcli / Releases & Gists / gh gist create

gh gist create

Share a snippet in seconds

gh gist create turns a file, several files, or piped input into a GitHub gist and hands you back the URL. It's the quickest way to share a log, a config, or a code snippet from the terminal.

Quick answer
gh gist create script.sh

Syntax

gh gist create [<files>... | -] [flags]

Examples

Create a secret gist from a file

gh gist create notes.md

Create a public gist with a description

gh gist create app.py --public --desc "example"

Gist from piped output

cat error.log | gh gist create -

Bundle several files into one gist

gh gist create main.go go.mod

Create and open in the browser

gh gist create snippet.js --web

Options & flags

FlagWhat it does
-p, --publicMake the gist public (default is secret).
-d, --descDescription for the gist.
-f, --filenameSet the filename when reading from stdin.
-w, --webOpen the new gist in the browser.

How to use gh gist create, step by step

  1. Pick the file(s) you want to share.
  2. Run gh gist create file.txt, or pipe with cmd | gh gist create -.
  3. Add --public if it should be discoverable; the default is secret.
  4. gh prints the gist URL — copy and share it.

Common errors and fixes

a gist file cannot be blank

One of the files is empty. gists can't contain empty files — add content or remove the file.

HTTP 401: Requires authentication

Sign in first with gh auth login; creating gists needs the gist scope.

Related commands

Frequently asked questions

How do I create a gist from the command line?

Run gh gist create <file>, for example gh gist create notes.md. To share piped output, use cmd | gh gist create - and gh reads from standard input.

Are gh gists public or secret by default?

Secret by default. Add --public to make the gist discoverable and listed on your profile.

Can I put multiple files in one gist?

Yes. List them all: gh gist create main.go go.mod bundles the files into a single gist.