LinuxCommandLibrary

gh-gist

Create, view, and manage GitHub Gists

TLDR

Create a new Gist from one or more files

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

Create a new Gist with a specific [desc]ription
$ gh gist 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 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 [flags]

PARAMETERS

create
    Creates a new gist from one or more files, or from standard input.
Usage: gh gist create [<file>...] [--desc <string>] [--public] [--web]
Options:
--desc <string>: A description for the gist.
--public: Makes the new gist public (default is secret).
--web: Opens the newly created gist in a web browser.
[<file>...]: One or more files to include in the gist. Use '-' for standard input.

list
    Lists your gists.
Usage: gh gist list [--limit <int>] [--public] [--secret]
Options:
--limit <int>: Maximum number of gists to list (default: 30).
--public: Lists only public gists.
--secret: Lists only secret gists.

view
    Views the content of a specific gist.
Usage: gh gist view {<gist id> | <gist url>} [--files <string>] [--raw]
Arguments:
{<gist id> | <gist url>}: The ID or full URL of the gist to view.
Options:
--files <string>: Comma-separated list of specific files within the gist to display.
--raw: Prints the raw content of the gist files, rather than formatted output.

edit
    Edits an existing gist, allowing changes to its description, files, or visibility.
Usage: gh gist edit {<gist id> | <gist url>} [<file>...] [--add <string>] [--desc <string>] [--filename <string>] [--public]
Arguments:
{<gist id> | <gist url>}: The ID or full URL of the gist to edit.
[<file>...]: Files to update in the gist. Opens in editor if not specified.
Options:
--add <string>: Adds a new file to the gist.
--desc <string>: Provides a new description for the gist.
--filename <string>: Specifies the filename to edit when multiple files exist.
--public: Makes the gist public (if it's currently secret).

delete
    Deletes a gist.
Usage: gh gist delete {<gist id> | <gist url>} [--confirm]
Arguments:
{<gist id> | <gist url>}: The ID or full URL of the gist to delete.
Options:
--confirm: Confirms deletion without an interactive prompt.

fork
    Forks a gist, creating a copy under your account.
Usage: gh gist fork {<gist id> | <gist url>}
Arguments:
{<gist id> | <gist url>}: The ID or full URL of the gist to fork.

star
    Stars a gist.
Usage: gh gist star {<gist id> | <gist url>}
Arguments:
{<gist id> | <gist url>}: The ID or full URL of the gist to star.

unstar
    Unstars a previously starred gist.
Usage: gh gist unstar {<gist id> | <gist url>}
Arguments:
{<gist id> | <gist url>}: The ID or full URL of the gist to unstar.

-h, --help
    Displays help information for the gh gist command or its subcommands. Available for each subcommand (e.g., gh gist create --help).

DESCRIPTION

gh-gist is a powerful subcommand of the GitHub CLI (gh) designed for seamless interaction with GitHub Gists directly from your terminal. It allows users to perform a wide array of operations on their gists, including creating new gists from files or standard input, listing existing gists, viewing their content, editing them, and even deleting them. Beyond basic CRUD operations, gh-gist also supports actions like forking gists, and starring or unstarring them, mirroring the functionality available on the GitHub website. This command-line interface streamlines workflows for developers who frequently use gists for sharing code snippets, notes, or configuration files, eliminating the need to switch between the terminal and a web browser. It integrates well into scripting and automation tasks, enhancing productivity for GitHub users.

CAVEATS

  • Requires the GitHub CLI (gh) to be installed and properly authenticated with your GitHub account (via gh auth login).
  • Active internet connectivity is essential for all operations.
  • GitHub API rate limits apply to gist operations; excessive requests may temporarily block access.
  • Interactive editing with gh gist edit relies on your EDITOR or VISUAL environment variables to launch a text editor. Ensure these are set up correctly.

AUTHENTICATION

All gh gist operations require the user to be authenticated with GitHub. This is typically achieved by running gh auth login and following the prompts.

GIST IDENTIFIERS

When specifying a gist for commands like view, edit, delete, fork, star, or unstar, you can use either the unique 32-character gist ID (e.g., 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6') or the full URL to the gist (e.g., 'https://gist.github.com/username/a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6').

FILE HANDLING

When creating or editing gists, you can provide local file paths. For gh gist create, using '-' as the file argument tells the command to read content from standard input (stdin).

HISTORY

The gh command-line tool was developed by GitHub to provide a native CLI for interacting with various GitHub services. gh-gist is an integral part of this tool, introduced to enable seamless management of gists directly from the terminal. Its development aims to improve developer productivity by allowing common GitHub operations, including gist management, to be performed without leaving the command line, thereby complementing and extending the functionality available through the web interface.

SEE ALSO

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

Copied to clipboard