gh
Interact with GitHub from the command line
TLDR
Clone a GitHub repository locally
Create a new issue
View and filter the open issues of the current repository
View an issue in the default web browser
Create a pull request
View a pull request in the default web browser
Check out a specific pull request locally
Check the status of a repository's pull requests
SYNOPSIS
gh command [subcommand] [flags]
gh auth login
gh pr create
gh issue list
gh help [command]
PARAMETERS
--help, -h
Show help for a specific command or the global usage.
--version, -v
Print the version of gh CLI.
--verbose
Enable verbose output, useful for debugging.
--hostname host
Specify the GitHub hostname to interact with (default: github.com).
--repo owner/repo
Specify the GitHub repository to operate on. Defaults to the current directory's repository.
--json fields
Output in JSON format with specified fields, available for certain commands (e.g., gh pr view).
subcommand_flags
Each gh subcommand (e.g., pr, issue, release) has its own set of specific flags that control its behavior. Use gh <command> help to see available flags.
DESCRIPTION
gh is the official command-line interface for GitHub. It brings pull requests, issues, Gists, releases, and other GitHub functionalities directly to your terminal. Instead of navigating the web interface, developers can perform common tasks like creating repositories, managing pull requests, viewing issues, or interacting with GitHub Actions workflows from their command line. This significantly streamlines workflows, enables scripting and automation of GitHub interactions, and integrates GitHub more deeply into the developer's local environment. While gh complements and often enhances Git operations, it does not replace Git itself; rather, it extends Git's capabilities with GitHub-specific features.
CAVEATS
gh requires an active internet connection to interact with GitHub.
Prior authentication using gh auth login is necessary to perform most operations.
It's not a full replacement for Git; core Git operations like git add, git commit, and git push are still performed using the git command.
AUTHENTICATION
gh manages authentication securely, primarily through OAuth. The first time you use a command requiring authentication (e.g., gh pr create), it will prompt you to run gh auth login. This command guides you through a browser-based authentication flow, obtaining a secure token that gh stores locally for future use. It also supports authentication via GitHub Enterprise Server instances.
EXTENSIBILITY
gh supports custom extensions, allowing users to create their own subcommands. These extensions can be written in any language and are executed as separate processes. This feature enables users and communities to build specialized tools and workflows on top of the existing gh functionality, further tailoring it to specific needs. Extensions are installed via gh extension install <repo>.
HISTORY
The gh CLI was developed by GitHub Inc. and officially released in 2020. It was designed to provide a unified and official command-line experience for GitHub, aiming to supersede community-driven efforts like the hub tool (which was an extension to Git). Its development is open source and actively maintained, with frequent updates adding new features and improving existing ones to keep pace with GitHub's web platform.