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.
这个资产会安全暂存
这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。
npx -y tokrepo@latest install 6ed07b71-35cb-11f1-9bc6-00163e2b0d79 --target codex先暂存文件;激活前需要读取暂存 README 和安装计划。
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.
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.
How to use
- Install gh:
brew install gh # macOS
sudo apt install gh # Debian/Ubuntu
winget install GitHub.cli # Windows
- Authenticate:
gh auth login
- 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
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'
Related on TokRepo
- AI Tools for Coding — Developer productivity tools
- DevOps Tools — CI/CD and automation
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.
Common pitfalls
- gh auth login stores credentials in the system keychain; on headless servers, use
gh auth login --with-tokento authenticate with a personal access token via stdin. - The
gh apicommand provides direct GitHub API access but requires understanding REST/GraphQL endpoints; use--jqfor 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.
常见问题
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.
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.
Yes. gh works with GitHub.com and GitHub Enterprise Server. Use gh auth login to authenticate with your enterprise instance.
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.
Yes. GitHub CLI is open-source under the MIT license and free to use. It is developed and maintained by GitHub.
引用来源 (3)
- GitHub CLI Official— GitHub CLI brings GitHub to the terminal
- GitHub CLI GitHub— gh is open-source under MIT license
- GitHub CLI Manual— GitHub CLI documentation and command reference
讨论
相关资产
App Store Connect CLI — Scriptable CLI for Apple App Distribution
App Store Connect CLI is a fast, JSON-first command-line tool for automating Apple App Store Connect workflows. It handles TestFlight builds, submissions, signing, analytics, and subscriptions without interactive prompts.
HTTPie CLI — Modern User-Friendly Command-Line HTTP Client
HTTPie is a modern, user-friendly command-line HTTP client for the API era. Intuitive syntax, formatted and colorized output, JSON support, sessions, authentication, file uploads, and plugins. The friendly alternative to curl for API exploration.
gh-dash — A Beautiful Terminal Dashboard for GitHub
A terminal UI extension for the GitHub CLI that displays pull requests, issues, and repository activity in a rich interactive dashboard.
Commander.js — The Complete Solution for Node.js CLI Programs
A Node.js library for building command-line interfaces with support for commands, options, arguments, and auto-generated help.