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.
gh gist create script.shSyntax
gh gist create [<files>... | -] [flags]Examples
Create a secret gist from a file
gh gist create notes.mdCreate 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.modCreate and open in the browser
gh gist create snippet.js --webOptions & flags
| Flag | What it does |
|---|---|
| -p, --public | Make the gist public (default is secret). |
| -d, --desc | Description for the gist. |
| -f, --filename | Set the filename when reading from stdin. |
| -w, --web | Open the new gist in the browser. |
How to use gh gist create, step by step
- Pick the file(s) you want to share.
- Run
gh gist create file.txt, or pipe withcmd | gh gist create -. - Add
--publicif it should be discoverable; the default is secret. - 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.