gh

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub CLI (gh)

GitHub CLI (gh)

Overview

概述

Use
gh
for authenticated GitHub operations from the terminal. Prefer explicit, idempotent commands and report URLs back to the user.
使用
gh
在终端中执行经过身份验证的GitHub操作。优先使用显式、幂等的命令,并将操作生成的URL返回给用户。

Quick checks

快速检查

  • Auth status:
bash
gh auth status
  • Current repo context:
bash
gh repo view --json nameWithOwner,url,defaultBranchRef
  • 认证状态:
bash
gh auth status
  • 当前仓库上下文:
bash
gh repo view --json nameWithOwner,url,defaultBranchRef

Core workflows

核心工作流

Repo create (private by default)

创建仓库(默认私有)

bash
gh repo create OWNER/NAME --private --confirm --description "..."
If running inside a local repo, use
--source . --remote origin --push
.
bash
gh repo create OWNER/NAME --private --confirm --description "..."
如果在本地仓库目录内执行命令,请使用
--source . --remote origin --push
参数。

Clone / fork

克隆 / 分叉

bash
gh repo clone OWNER/NAME
bash
gh repo fork OWNER/NAME --clone
bash
gh repo clone OWNER/NAME
bash
gh repo fork OWNER/NAME --clone

Issues

Issues

  • List:
bash
gh issue list --limit 20
  • Create:
bash
gh issue create --title "..." --body "..."
  • Comment:
bash
gh issue comment <num> --body "..."
  • 列出:
bash
gh issue list --limit 20
  • 创建:
bash
gh issue create --title "..." --body "..."
  • 评论:
bash
gh issue comment <num> --body "..."

Pull requests

Pull requests

  • Create from current branch:
bash
gh pr create --title "..." --body "..."
  • List:
bash
gh pr list --limit 20
  • View:
bash
gh pr view <num> --web
  • Merge (use explicit method):
bash
gh pr merge <num> --merge
  • 从当前分支创建:
bash
gh pr create --title "..." --body "..."
  • 列出:
bash
gh pr list --limit 20
  • 查看:
bash
gh pr view <num> --web
  • 合并(使用显式合并方式):
bash
gh pr merge <num> --merge

Releases

版本发布

bash
gh release create vX.Y.Z --title "vX.Y.Z" --notes "..."
bash
gh release create vX.Y.Z --title "vX.Y.Z" --notes "..."

Safety notes

安全注意事项

  • Confirm the target repo/owner before destructive actions (delete, force push).
  • For private repos, ensure
    --private
    is set on create.
  • Prefer
    --confirm
    to avoid interactive prompts in automation.
  • 执行破坏性操作(删除、强制推送)前,请确认目标仓库/所有者是否正确。
  • 创建私有仓库时,请确保设置了
    --private
    参数。
  • 在自动化场景中优先使用
    --confirm
    参数避免交互式提示。