LinuxCommandLibrary

gh-gist

Create, view, and manage GitHub Gists

TLDR

Create a new Gist from one or more files

$ gh gist [[new|create]] [path/to/file1 path/to/file2 ...]
copy

Create a new Gist with a specific [desc]ription
$ gh gist [[new|create]] [path/to/file1 path/to/file2 ...] [[-d|--desc]] "[description]"
copy

Edit a Gist
$ gh gist edit [id|url]
copy

List up to 42 Gists owned by the currently logged in user
$ gh gist [[ls|list]] [[-L|--limit]] 42
copy

View a Gist in the default browser without rendering Markdown
$ gh gist view [id|url] [[-w|--web]] [[-r|--raw]]
copy

SYNOPSIS

gh gist <create|list|view|edit|delete> [options] [arguments]

PARAMETERS

create
    Create a new gist from files or stdin

-d, --description <string>
    Description for the new gist (create/edit)

-f, --filename <string[]>
    Filenames for gist files (create)

-p, --public
    Make gist public instead of secret (create)

-w, --web
    Open gist URL in browser (create/view)

list
    List your gists

-l, --limit <int>
    Max gists to fetch (default 30, list)

--public
    Show only public gists (list)

view <ID|URL>
    View gist by ID or URL

delete <ID|URL>
    Delete gist(s) by ID/URL

-d, --delete <string>
    Delete multiple gists (delete)

edit <ID|URL>
    Edit gist by ID/URL

-a, --add <string[]>
    Add new files to gist (edit)

-r, --rename <string[]>
    Rename existing files (edit)

-R, --remove <string[]>
    Remove files from gist (edit)

DESCRIPTION

gh gist is a subcommand of the GitHub CLI (gh), enabling seamless management of GitHub Gists from the Linux terminal.

Gists are lightweight code-sharing snippets hosted on GitHub, useful for quick shares or notes. This command supports creating gists from files or stdin (public or secret), listing your gists (with filters), viewing details (including raw files), editing metadata/files, and deleting by ID/URL.

Key features include custom filenames, descriptions, web browser opening, and pagination. It integrates with gh's auth system for secure API access. Ideal for developers automating workflows without leaving the shell.

Requires gh installed (e.g., via package managers like apt/snap) and authenticated via gh auth login. Handles multiple files, stdin piping, and error feedback clearly.

CAVEATS

Requires gh v2.0+ and GitHub authentication. No support for forking gists or comments. Rate-limited by GitHub API. Secret gists visible to you only.

EXAMPLES

gh gist create file1.txt
echo 'code' | gh gist create -f script.sh
gh gist list -l 10
gh gist view https://gist.github.com/...

AUTHENTICATION

Run gh auth login first. Uses GitHub token for API calls.

HISTORY

Introduced in GitHub CLI v0.5.0 (2020); matured in v2.0+ with full CRUD support. Developed by GitHub to replace hub for modern workflows.

SEE ALSO

gh(1), git(1), curl(1)

Copied to clipboard