ConfigsApr 11, 2026·2 min read

GitHub CLI (gh) — GitHub Official Command Line Tool

GitHub CLI brings GitHub to your terminal. Create PRs, manage issues, review code, run Actions, browse releases — without leaving the command line. Written in Go and the official cross-platform tool from GitHub.

TL;DR
GitHub CLI lets you create PRs, manage issues, run Actions, and review code from the terminal.
§01

What it is

GitHub CLI (gh) is the official command-line tool for GitHub. It brings pull requests, issues, code review, Actions workflows, releases, and repository management to your terminal. Written in Go, gh works on macOS, Linux, and Windows.

gh targets developers who prefer the terminal over the GitHub web interface. It integrates with Git workflows so you can create PRs, review diffs, manage issues, and trigger CI/CD without opening a browser.

§02

How it saves time or tokens

gh eliminates context switching between your terminal and the GitHub web interface. Creating a pull request is a single command instead of navigating to the web UI. Viewing CI status, approving reviews, and merging PRs all happen from the terminal. For scripting and automation, gh provides structured JSON output and a powerful gh api command for any GitHub API endpoint.

§03

How to use

  1. Install gh:
brew install gh            # macOS
sudo apt install gh        # Debian/Ubuntu
winget install GitHub.cli  # Windows
  1. Authenticate:
gh auth login
  1. Common workflows:
gh pr create --title 'Add feature' --body 'Description here'
gh pr list
gh pr checkout 42
gh pr merge 42 --squash
gh issue create --title 'Bug report' --body 'Details'
gh run list
gh run watch
§04

Example

# Create a repo and push
gh repo create my-project --public --source=. --push

# Create PR with reviewers
gh pr create --title 'Refactor auth module' \
  --body 'Simplified OAuth flow' \
  --reviewer alice,bob \
  --label enhancement

# View PR diff and approve
gh pr diff 42
gh pr review 42 --approve

# Scripting with JSON output
gh pr list --json number,title,state | jq '.[] | select(.state=="OPEN")'

# Call any GitHub API endpoint
gh api repos/{owner}/{repo}/actions/runs --jq '.workflow_runs[0].status'
§05

Related on TokRepo

This tool integrates with standard development workflows and requires minimal configuration to get started. It is available as open-source software with documentation and community support through the official repository. The project follows semantic versioning for stable releases.

For teams evaluating this tool, the key advantage is reducing manual work in repetitive tasks. The automation provided by the built-in features means less custom code to maintain and fewer integration points to manage. This translates directly to lower maintenance costs and faster iteration cycles.

§06

Common pitfalls

  • gh auth login stores credentials in the system keychain; on headless servers, use gh auth login --with-token to authenticate with a personal access token via stdin.
  • The gh api command provides direct GitHub API access but requires understanding REST/GraphQL endpoints; use --jq for filtering JSON responses.
  • gh uses the current Git remote to determine the repository; if you have multiple remotes, specify the repo with --repo owner/name.

Frequently Asked Questions

Does gh replace git?+

No. gh complements git by adding GitHub-specific features (PRs, issues, Actions, releases) to the command line. You still use git for commits, branches, and local operations.

Can I use gh in CI/CD pipelines?+

Yes. gh is commonly used in GitHub Actions workflows for creating releases, commenting on PRs, and managing issues. Authenticate with the GITHUB_TOKEN environment variable.

Does gh support GitHub Enterprise?+

Yes. gh works with GitHub.com and GitHub Enterprise Server. Use gh auth login to authenticate with your enterprise instance.

Can I script with gh?+

Yes. Most gh commands support --json output for structured data. The gh api command provides access to any GitHub API endpoint. Combined with jq, gh is a powerful scripting tool for GitHub automation.

Is gh free?+

Yes. GitHub CLI is open-source under the MIT license and free to use. It is developed and maintained by GitHub.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets