LinuxCommandLibrary

gh

Interact with GitHub from the command line

TLDR

Clone a GitHub repository locally

$ gh repo clone [owner]/[repository]
copy

Create a new issue
$ gh issue [[new|create]]
copy

View and filter the open issues of the current repository
$ gh issue [[ls|list]]
copy

View an issue in the default web browser
$ gh issue view [[-w|--web]] [issue_number|url]
copy

Create a pull request
$ gh pr [[new|create]]
copy

View a pull request in the default web browser
$ gh pr view [[-w|--web]] [pr_number|url|branch]
copy

Check out a specific pull request locally
$ gh [[co|pr checkout]] [pr_number|url|branch]
copy

Check the status of a repository's pull requests
$ gh pr status
copy

SYNOPSIS

gh [global flags] <command> [<args>...]
e.g., gh pr create --title 'Fix bug' --body 'Details'

PARAMETERS

-C, --cwd DIR
    Change working directory before running command

-R, --repo [HOST/]OWNER/REPO
    Select another repository matching the HOST/OWNER/REPO format

--help
    Show help for command

--version
    Show gh version

-q, --quiet
    Disable progress output; use plain error messages

-v, --verbose
    Output verbose logs

--paginate
    Enable pagination (default)

--no-pager
    Disable pagination; output to stdout directly

--no-color
    Disable colored output

--color WHEN
    Control when to use colored output: always, never, or auto (default)

DESCRIPTION

The gh command is GitHub's official command-line interface (CLI), designed to extend git with powerful GitHub-specific features directly from the terminal. It enables users to manage repositories, create and review pull requests, handle issues, releases, workflows, and more without leaving the command line.

Key capabilities include authenticating with GitHub, cloning repositories with gh repo clone, creating pull requests via gh pr create, checking status with gh pr status, and viewing issues with gh issue list. It supports interactive modes for complex tasks, like drafting PRs or resolving threads.

gh integrates seamlessly with existing git workflows, auto-detecting repositories and providing context-aware commands. Written in Go, it's fast, cross-platform (Linux, macOS, Windows), and extensible via extensions. Authentication uses GitHub CLI login, supporting browser flow, tokens, or SSH.

Ideal for developers automating CI/CD, scripting GitHub interactions, or preferring terminal efficiency over web UI. It reduces context-switching and boosts productivity in GitHub-centric projects.

CAVEATS

Requires GitHub authentication via gh auth login for most operations; public repos work anonymously. Not a git replacement—use alongside git. Rate-limited by GitHub API; enterprise support needs configuration.

INSTALLATION

Linux: sudo apt install gh (Debian/Ubuntu) or download from GitHub releases. Use brew install gh on macOS.

AUTHENTICATION

Run gh auth login to authenticate interactively (browser/CLI/token). Supports GitHub.com, Enterprise, and GitHub AE.

COMMON SUBCOMMANDS

repo (manage repos), pr (pull requests), issue (issues), release (releases), workflow (Actions). Use gh <tab> for completions.

HISTORY

Announced by GitHub in February 2020 as open-source CLI (MIT license, written in Go). Replaces deprecated hub tool. Rapid development with v0.1 in 2019; current stable releases (v2.x as of 2023) add features like Copilot integration and AI prompts.

SEE ALSO

git(1), hub(1), git-lfs(1)

Copied to clipboard