Command Palette

Search for a command to run...

GitHubGitHub

GitHub CLI Installation Guide

Install GitHub CLI 2.102 on Linux, macOS and Windows, authenticate with GitHub, and manage pull requests, issues, workflows and releases from your terminal.

GitHub CLI (gh) is GitHub's official command-line tool. It brings pull requests, issues, workflows and releases into the terminal, next to where you already work with git.

System Requirements

  • A 64-bit operating system: Linux, macOS or Windows
  • git on your PATH — gh shells out to it for most commands
  • A GitHub account (GitHub.com, GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+)

Installation Instructions

Debian / Ubuntu / Raspberry Pi (official)

# Install the keyring and the repository in one step
(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \
  && sudo mkdir -p -m 755 /etc/apt/keyrings \
  && out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
  && cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
  && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
  && sudo mkdir -p -m 755 /etc/apt/sources.list.d \
  && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/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
 
# Verify
gh --version

Authentication

# Interactive login — choose the host, protocol and browser or device code
gh auth login
 
# For a headless machine, print a code instead of opening a browser
gh auth login --web
 
# Choose the git protocol used for clones (ssh or https)
gh auth login --git-protocol ssh
 
# For GitHub Enterprise Server
gh auth login --hostname ghe.example.com
# Check which accounts are configured
gh auth status
 
# Switch between accounts
gh auth switch --hostname github.com --user octocat
 
# Let gh configure git to use its credentials
gh auth setup-git
 
# Refresh an expiring token
gh auth refresh --scopes repo,workflow
 
# Print the token (for scripts)
gh auth token

In CI

# GitHub Actions
env:
  GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr list
# Or use the fine-grained token
export GH_TOKEN=ghp_xxxxxxxxxxxx
export GH_HOST=github.com
VariablePurpose
GH_TOKENToken used for API requests
GH_ENTERPRISE_TOKENToken for GitHub Enterprise Server
GH_HOSTDefault hostname, for example ghe.example.com
GH_EDITOREditor used by gh pr create and friends
GH_BROWSERBrowser opened by gh browse and gh pr create
GH_REPODefault repository, so you can skip the flags
GH_TELEMETRYSet to 0 to disable usage telemetry

Everyday Commands

Pull Requests

# Create a pull request from the current branch
gh pr create --title "Add login" --body "Closes #42" --base main
 
# List, view and check out
gh pr list --state open
gh pr view 123 --web
gh pr checkout 123
 
# Review, merge and clean up
gh pr diff 123
gh pr review 123 --approve
gh pr merge 123 --squash --delete-branch
gh pr update-branch 123

Issues and Pull Requests

# Search across GitHub
gh search issues "flaky test" --owner octocat
gh search code "retry" --repo cli/cli
gh search repos "devops" --limit 20
 
# Issues
gh issue create --title "Bug" --body "Details" --label bug
gh issue list --assignee @me
gh issue close 42 --comment "Fixed in #43"

Workflows and Runs

# List the workflows and trigger one
gh workflow list
gh workflow run deploy.yml --ref main
 
# Watch a run
gh run list --workflow ci.yml
gh run watch 123456789
gh run view 123456789 --log-failed
gh run rerun 123456789 --failed
gh run download 123456789 --name artifacts

Repositories

# Clone, fork and create
gh repo clone cli/cli
gh repo fork cli/cli --clone
gh repo create my-project --private --push
 
# Browse files in the repository
gh repo view --web
gh browse --branch main

Secrets, Variables and Releases

# Repository secrets and variables
gh secret set API_KEY --body "value"
gh secret list
gh variable set LOG_LEVEL --body "debug"
 
# Releases
gh release create v1.2.0 --generate-notes
gh release upload v1.2.0 ./dist/app.tar.gz
gh release view v1.2.0

Power Features

# Verify a build attestation
gh attestation verify oci://ghcr.io/owner/image:v1 --repo owner/repo
 
# Install the agent skill that lets a coding agent drive gh
gh skill install cli/cli gh --scope user
 
# Extensions, aliases and configuration
gh extension install dlvhdr/gh-dash
gh alias set co "pr checkout"
gh config set editor vim

Troubleshooting

Best Practices

  1. Install from the official repository — the community packages lag and the Debian/Ubuntu one is currently broken.
  2. Run gh auth login once per machine and use gh auth setup-git so git uses the same credentials.
  3. Set GH_REPO in CI to avoid repeating -R on every command.
  4. Use GITHUB_TOKEN in GitHub Actions, never a personal access token.
  5. Prefer gh api for anything the CLI does not wrap — it is the full REST API.
  6. Set GH_TELEMETRY=0 if your organisation does not want usage telemetry.
  7. Pin the CLI version in CI images so a new release cannot change your pipeline.
  8. Verify releases with gh attestation verify before you trust a downloaded binary.

Next Steps