# 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. ## Install Save in your project root: ## Quick Use ```bash # Install brew install gh # macOS sudo apt install gh # Debian/Ubuntu (needs PPA) winget install GitHub.cli # Windows # Auth gh auth login ``` Common commands: ```bash gh repo create my-app --public --source=. --push gh pr create --title "Add feature" --body "Description" gh pr list gh pr view 42 --web gh pr checkout 42 gh pr review 42 --approve gh pr merge 42 --squash --delete-branch gh issue create --title "Bug" --body "Steps to reproduce" gh issue list --assignee @me gh run list # Actions runs gh run view gh run watch # Tail a running workflow gh release create v1.0.0 --generate-notes gh gist create file.txt --public gh api repos/:owner/:repo/stargazers ``` ## Intro GitHub CLI (binary `gh`) is the official command line tool for GitHub. Written in Go by the GitHub team, it brings issues, pull requests, Actions, releases, gists, and the REST/GraphQL API directly to your terminal. Cross-platform and works with GitHub.com + GitHub Enterprise. - **Repo**: https://github.com/cli/cli - **Stars**: 43K+ - **Language**: Go - **License**: MIT ## What gh Does - **Repos** — create, clone, fork, view, archive - **Pull requests** — create, checkout, review, merge - **Issues** — create, close, comment, assign, label - **Actions** — list runs, view logs, rerun, watch - **Releases** — create, upload assets, generate notes - **Gists** — create, list, view - **API passthrough** — `gh api` for any REST/GraphQL endpoint - **Extensions** — install community extensions (`gh extension install`) - **Codespaces** — create, list, ssh into Codespaces - **Copilot integration** — `gh copilot explain` / `gh copilot suggest` ## Architecture Go CLI that hits the GitHub REST + GraphQL APIs. Auth stored via OAuth device flow in keyring. Commands are composable (`--json fields | jq`). Extensions add new subcommands by installing binaries or scripts into `~/.local/share/gh/extensions`. ## Self-Hosting CLI tool. Authenticates to github.com or your GHES instance. ## Key Features - Full PR workflow - Issue management - Actions monitoring and rerun - Release management - Gist creation - GraphQL API passthrough - Extension system - Copilot CLI integration - Cross-platform - JSON output for scripting ## Comparison | Tool | Platform | Auth | Extensions | |---|---|---|---| | gh | GitHub | OAuth | Yes | | glab | GitLab | Token | Limited | | hub | GitHub (legacy) | Token | No | | tea | Gitea | Token | No | | bitbucket-cli | Bitbucket | Token | No | ## 常见问题 FAQ **Q: hub 和 gh 有啥区别?** A: hub 是旧版第三方 CLI,gh 是 GitHub 官方出品(2020+),功能更全、体验更好。hub 已停止新功能。 **Q: 能脚本化吗?** A: 能。`gh pr list --json title,url --jq .[].url` 输出 JSON,配合 jq 很容易脚本化 CI 任务。 **Q: 可以 API 直接调用吗?** A: 可以。`gh api /repos/owner/repo/issues` 任意 REST endpoint;`gh api graphql -f query=...` 执行 GraphQL。 ## 来源与致谢 Sources - Docs: https://cli.github.com/manual - GitHub: https://github.com/cli/cli - License: MIT --- Source: https://tokrepo.com/en/workflows/6ed07b71-35cb-11f1-9bc6-00163e2b0d79 Author: AI Open Source