Skip to content

Github CLI

Getting Started

Installation

Windows

ToolInstallUpgrade
WinGetwinget install --id Github.cliwinget upgrade --id GitHub.cli
Scoopscoop install ghscoop update gh
Chocochoco install ghchoco upgrade gh

{.show-header}

Mac OS

ToolInstallUpgrade
Brewbrew install ghbrew upgrade gh
MacPortssudo port install ghsudo port selfupdate && sudo port upgrade gh

{.show-header}

Linux

See the install instructions for other Linux distributions.

Installation Script:

Terminal window
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y

Basic Usage

Help and Documentation

Display command options:

CommandDescription
gh help [command]Help provides help for any command in the application. Simply type gh help [path to command] for full details.

Authentication

CommandDescription
gh auth loginDefault authentication with web-based browser
gh auth logoutRemoves the authentication configuration for a host
gh auth refreshExpand or fix the permission scopes for stored credentials
gh auth setup-gitConfigures git to use GitHub CLI as a credential helper
gh auth statusVerifies and displays information about your authentication state
gh auth tokenPrint the auth token gh is configured to use

With Github token:

Terminal window
$ gh auth --with-token < token.txt

Repository Management

General

CommandDescription
gh repo createCreate a new GitHub repository
gh repo list [target]List repositories owned by a user or organization

Targets

CommandDescription
gh repo archive [repo]Archive a GitHub repository
gh repo clone [dir]Clone a GitHub repository locally
gh repo delete [repo]Delete a GitHub repository
gh repo deploy-keyManage deploy keys in a repository
gh repo edit [repo]Edit repository settings
gh repo fork [repo]Create a fork of a repository
gh repo rename [name]Rename a GitHub repository
gh repo set-default [repo]This command sets the default remote repository
gh repo sync [dest-repo]Sync destination repository from source repository
gh repo view [repo]Display the description and the README of a GitHub repository.

Issues

Search Issues

CommandDescription
gh search issues [query]Search for issues on GitHub

Examples

Terminal window
# search issues matching set of keywords "readme" and "typo"
$ gh search issues readme typo
# search issues matching phrase "broken feature"
$ gh search issues "broken feature"
# search issues and pull requests in cli organization
$ gh search issues --include-prs --owner=cli
# search open issues assigned to yourself
$ gh search issues --assignee=@me --state=open
# search issues with numerous comments
$ gh search issues --comments=">100"
# search issues without label "bug"
$ gh search issues -- -label:bug

Pull Requests

Pull Request Actions

CommandDescription
gh pr createCreate a pull request on GitHub
gh pr listList pull requests in a GitHub repository
gh pr statusShow status of relevant pull requests

Example

Terminal window
$ gh pr status

Sample Output:

Current branch
#12 Remove the test feature [user:patch-2]
- All checks failing - Review required
Created by you
You have no open pull requests
Requesting a code review from you
#13 Fix tests [branch]
- 3/4 checks failing - Review required
#15 New feature [branch]
- Checks passing - Approved

Github Actions

General Actions

CommandDescription
gh workflow disableDisable a workflow, preventing it from running or showing up when listing workflows
gh workflow enableEnable a workflow, allowing it to be run and show up when listing workflows
gh workflow listList workflow files, hiding disabled workflows by default
gh workflow runCreate a workflow_dispatch event for a given workflow
gh workflow viewView the summary of a workflow

Running Actions

CommandDescription
gh run cancelCancel a workflow run
gh run deleteDelete a workflow run
gh run downloadDownload artifacts generated by a GitHub Actions workflow run
gh run listList recent workflow runs
gh run rerunRerun an entire run, only failed jobs, or a specific job from a run
gh run viewView a summary of a workflow run
gh run watchWatch a run until it completes, showing its progress

Aliases

General Alias Settings

CommandDescription
gh alias deleteDelete set aliases
gh alias importImport aliases from the contents of a YAML file
gh alias listPrints out all of the aliases gh is configured to use
gh alias setDefine a word that will expand to a full gh command when invoked

Releases

General Actions

CommandDescription
gh release createCreate a new GitHub Release for a repository
gh release listList releases in a repository

Target Commands

CommandDescription
gh release deleteDelete a release
gh release delete-assetDelete an asset from a release
gh release downloadDownload assets from a GitHub release
gh release editEdit a release
gh release uploadUpload asset files to a GitHub Release
gh release viewView information about a GitHub Release

Configuration

Targeted Settings

CommandDescription
gh config clear-cacheClear the cli cache
gh config getPrint the value of a given configuration key
gh config listPrint a list of configuration keys and values
gh config setUpdate configuration with a value for the given key