gh-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub CLI - Remote Analysis & Discovery
GitHub CLI - 远程分析与发现
Remote repository operations, codebase comparison, and code discovery without cloning.
无需克隆即可进行远程仓库操作、代码库对比和代码发现。
When to Use
适用场景
- Analyze repositories without cloning
- Compare codebases side-by-side
- Fetch specific files from any repo
- Find trending repositories and code patterns
- Search code across GitHub
- 无需克隆即可分析仓库
- 并排对比代码库
- 从任意仓库获取特定文件
- 发现热门仓库和代码模式
- 在GitHub上搜索代码
Quick Operations
快速操作
Fetch a file remotely
远程获取文件
bash
gh api repos/OWNER/REPO/contents/path/file.ts | jq -r '.content' | base64 -dbash
gh api repos/OWNER/REPO/contents/path/file.ts | jq -r '.content' | base64 -dGet directory listing
获取目录列表
bash
gh api repos/OWNER/REPO/contents/PATHbash
gh api repos/OWNER/REPO/contents/PATHSearch code
搜索代码
bash
gh search code "pattern" --language=typescriptbash
gh search code "pattern" --language=typescriptFind trending repos
发现热门仓库
bash
gh search repos --language=rust --sort stars --order descbash
gh search repos --language=rust --sort stars --order descCompare Two Codebases
对比两个代码库
Systematic workflow for comparing repositories to identify similarities and differences.
Example use: "Compare solana-fm/explorer-kit and tenequm/solana-idls"
用于对比仓库以识别异同的系统化流程。
示例用法:"Compare solana-fm/explorer-kit and tenequm/solana-idls"
Step 1: Fetch directory structures
步骤1:获取目录结构
bash
gh api repos/OWNER-A/REPO-A/contents/PATH > repo1.json
gh api repos/OWNER-B/REPO-B/contents/PATH > repo2.jsonIf comparing a monorepo package, specify the path (e.g., ).
packages/explorerkit-idlsbash
gh api repos/OWNER-A/REPO-A/contents/PATH > repo1.json
gh api repos/OWNER-B/REPO-B/contents/PATH > repo2.json如果对比的是单体仓库中的某个包,请指定路径(例如:)。
packages/explorerkit-idlsStep 2: Compare file lists
步骤2:对比文件列表
bash
jq -r '.[].name' repo1.json > repo1-files.txt
jq -r '.[].name' repo2.json > repo2-files.txt
diff repo1-files.txt repo2-files.txtShows files unique to each repo and common files.
bash
jq -r '.[].name' repo1.json > repo1-files.txt
jq -r '.[].name' repo2.json > repo2-files.txt
diff repo1-files.txt repo2-files.txt展示每个仓库独有的文件以及共同文件。
Step 3: Fetch key files for comparison
步骤3:获取关键文件进行对比
Compare package dependencies:
bash
gh api repos/OWNER-A/REPO-A/contents/package.json | jq -r '.content' | base64 -d > repo1-pkg.json
gh api repos/OWNER-B/REPO-B/contents/package.json | jq -r '.content' | base64 -d > repo2-pkg.jsonCompare main entry points:
bash
gh api repos/OWNER-A/REPO-A/contents/src/index.ts | jq -r '.content' | base64 -d > repo1-index.ts
gh api repos/OWNER-B/REPO-B/contents/src/index.ts | jq -r '.content' | base64 -d > repo2-index.ts对比包依赖:
bash
gh api repos/OWNER-A/REPO-A/contents/package.json | jq -r '.content' | base64 -d > repo1-pkg.json
gh api repos/OWNER-B/REPO-B/contents/package.json | jq -r '.content' | base64 -d > repo2-pkg.json对比主入口文件:
bash
gh api repos/OWNER-A/REPO-A/contents/src/index.ts | jq -r '.content' | base64 -d > repo1-index.ts
gh api repos/OWNER-B/REPO-B/contents/src/index.ts | jq -r '.content' | base64 -d > repo2-index.tsStep 4: Analyze differences
步骤4:分析差异
Compare the fetched files to identify:
API Surface
- What functions/classes are exported?
- Are the APIs similar or completely different?
Dependencies
- Shared dependencies (same approach)
- Different dependencies (different implementation)
Unique Features
- Features only in repo1
- Features only in repo2
For detailed comparison strategies, see references/comparison.md.
对比获取到的文件,识别以下内容:
API 接口
- 导出了哪些函数/类?
- API 是相似还是完全不同?
依赖项
- 共享依赖(实现方式相同)
- 不同依赖(实现方式不同)
独有功能
- 仅 repo1 具备的功能
- 仅 repo2 具备的功能
如需详细的对比策略,请参阅 references/comparison.md。
Discover Trending Content
发现热门内容
Find trending repositories
查找热门仓库
bash
undefinedbash
undefinedMost starred repos
星标最多的仓库
gh search repos --sort stars --order desc --limit 20
gh search repos --sort stars --order desc --limit 20
Trending in specific language
特定语言的热门仓库
gh search repos --language=rust --sort stars --order desc
gh search repos --language=rust --sort stars --order desc
Recently popular (created in last month)
近期热门(过去一个月创建)
gh search repos "created:>2024-10-01" --sort stars --order desc
gh search repos "created:>2024-10-01" --sort stars --order desc
Trending in specific topic
特定主题的热门仓库
gh search repos "topic:machine-learning" --sort stars --order desc
undefinedgh search repos "topic:machine-learning" --sort stars --order desc
undefinedDiscover popular code patterns
发现流行代码模式
bash
undefinedbash
undefinedFind popular implementations
查找流行实现
gh search code "function useWallet" --language=typescript --sort indexed
gh search code "function useWallet" --language=typescript --sort indexed
Find code in popular repos only
仅在热门仓库中查找代码
gh search code "implementation" "stars:>1000"
gh search code "implementation" "stars:>1000"
Search specific organization
搜索特定组织的代码
gh search code "authentication" --owner=anthropics
For complete discovery queries and patterns, see [references/discovery.md](references/discovery.md).gh search code "authentication" --owner=anthropics
如需完整的发现查询语句和模式,请参阅 [references/discovery.md](references/discovery.md)。Search Basics
搜索基础
Code search
代码搜索
bash
undefinedbash
undefinedSearch across all repositories
在所有仓库中搜索
gh search code "API endpoint" --language=python
gh search code "API endpoint" --language=python
Search in specific organization
在特定组织中搜索
gh search code "auth" --owner=anthropics
gh search code "auth" --owner=anthropics
Exclude results with negative qualifiers
使用否定限定符排除结果
gh search issues -- "bug report -label:wontfix"
undefinedgh search issues -- "bug report -label:wontfix"
undefinedIssue & PR search
议题与PR搜索
bash
undefinedbash
undefinedFind open bugs
查找开放的bug
gh search issues --label=bug --state=open
gh search issues --label=bug --state=open
Search assigned issues
搜索分配给自己的议题
gh search issues --assignee=@me --state=open
For advanced search syntax, see [references/search.md](references/search.md).gh search issues --assignee=@me --state=open
如需高级搜索语法,请参阅 [references/search.md](references/search.md)。Special Syntax
特殊语法
Field name inconsistencies
字段名称不一致
IMPORTANT: GitHub CLI uses inconsistent field names across commands:
| Field | | |
|---|---|---|
| Stars | | |
| Forks | | |
Examples:
bash
undefined重要提示:GitHub CLI 在不同命令中使用的字段名称不一致:
| 字段 | | |
|---|---|---|
| 星标 | | |
| 复刻 | | |
示例:
bash
undefined✅ Correct for gh repo view
✅ 适用于 gh repo view 的正确写法
gh repo view owner/repo --json stargazerCount,forkCount
gh repo view owner/repo --json stargazerCount,forkCount
✅ Correct for gh search repos
✅ 适用于 gh search repos 的正确写法
gh search repos "query" --json stargazersCount,forksCount
undefinedgh search repos "query" --json stargazersCount,forksCount
undefinedExcluding search results
排除搜索结果
When using negative qualifiers (like ), use to prevent the hyphen from being interpreted as a flag:
-label:bug--bash
gh search issues -- "query -label:bug"For more syntax gotchas, see references/syntax.md.
使用否定限定符(如 )时,请使用 避免连字符被解析为标志位:
-label:bug--bash
gh search issues -- "query -label:bug"如需了解更多语法陷阱,请参阅 references/syntax.md。
Advanced Workflows
高级工作流
For detailed documentation on specific workflows:
Core Workflows:
- remote-analysis.md - Advanced file fetching patterns
- comparison.md - Complete codebase comparison guide
- discovery.md - All trending and discovery queries
- search.md - Advanced search syntax
- syntax.md - Special syntax and command quirks
GitHub Operations:
- repositories.md - Repository operations
- pull_requests.md - PR workflows
- issues.md - Issue management
- actions.md - GitHub Actions
- releases.md - Release management
Setup & Configuration:
- getting_started.md - Installation and auth
- other.md - Environment variables, aliases, config
- extensions.md - CLI extensions
如需特定工作流的详细文档:
核心工作流:
- remote-analysis.md - 高级文件获取模式
- comparison.md - 完整代码库对比指南
- discovery.md - 所有热门内容与发现查询语句
- search.md - 高级搜索语法
- syntax.md - 特殊语法与命令特性
GitHub 操作:
- repositories.md - 仓库操作
- pull_requests.md - PR 工作流
- issues.md - 议题管理
- actions.md - GitHub Actions
- releases.md - 版本发布管理
设置与配置:
- getting_started.md - 安装与认证
- other.md - 环境变量、别名、配置
- extensions.md - CLI 扩展
Resources
资源
- Official docs: https://cli.github.com/manual/
- GitHub CLI: https://github.com/cli/cli
- Search syntax: https://docs.github.com/en/search-github