GitHub CLI (gh)
Overview
Use
gh for authenticated GitHub operations from the terminal. Prefer explicit, idempotent commands and report URLs back to the user.
Quick checks
gh auth status
CODEBLOCK1
Core workflows
Repo create (private by default)
gh repo create OWNER/NAME --private --confirm --description "..."
If running inside a local repo, use
--source . --remote origin --push.
Clone / fork
gh repo clone OWNER/NAME
CODEBLOCK4
Issues
gh issue list --limit 20
gh issue create --title "..." --body "..."
CODEBLOCK7
Pull requests
- - Create from current branch:
gh pr create --title "..." --body "..."
gh pr list --limit 20
gh pr view <num> --web
- - Merge (use explicit method):
CODEBLOCK11
Releases
CODEBLOCK12
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.
GitHub CLI (gh)
概述
使用 gh 在终端中执行经过身份验证的 GitHub 操作。优先使用显式、幂等的命令,并向用户返回 URL。
快速检查
bash
gh auth status
bash
gh repo view --json nameWithOwner,url,defaultBranchRef
核心工作流
创建仓库(默认私有)
bash
gh repo create OWNER/NAME --private --confirm --description ...
如果在本地仓库内运行,请使用 --source . --remote origin --push。
克隆/复刻
bash
gh repo clone OWNER/NAME
bash
gh repo fork OWNER/NAME --clone
议题
bash
gh issue list --limit 20
bash
gh issue create --title ... --body ...
bash
gh issue comment
--body ...
拉取请求
bash
gh pr create --title ... --body ...
bash
gh pr list --limit 20
bash
gh pr view --web
bash
gh pr merge --merge
发布版本
bash
gh release create vX.Y.Z --title vX.Y.Z --notes ...
安全提示
- - 在执行破坏性操作(删除、强制推送)前,确认目标仓库/所有者。
- 对于私有仓库,创建时确保设置 --private。
- 在自动化中优先使用 --confirm 以避免交互式提示。