Configs2026年4月11日·1 分钟阅读

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 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Stage only
信任
信任等级:Established
入口
step-1.md
安全暂存命令
npx -y tokrepo@latest install 6ed07b71-35cb-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

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.

常见问题

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.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产