github-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Search

GitHub 搜索

Quick Commands

快速命令

GoalCommand
Search repos
gh search repos "<query>" --limit 30
Search code
gh search code "<query>" --limit 30
Search issues
gh search issues "<query>" --limit 30
Search PRs
gh search prs "<query>" --limit 30
目标命令
搜索仓库
gh search repos "<query>" --limit 30
搜索代码
gh search code "<query>" --limit 30
搜索议题
gh search issues "<query>" --limit 30
搜索拉取请求
gh search prs "<query>" --limit 30

Direct API Search (Web-Exact Results)

直接API搜索(与网页结果完全一致)

For complex queries where
gh search repos
gives different results than web:
bash
undefined
gh search repos
的结果与网页端不一致时,可用于复杂查询:
bash
undefined

Template - URL-encodes query automatically

模板 - 自动对查询内容进行URL编码

gh api "search/repositories?q=$(printf '%s' 'YOUR_QUERY_HERE' | jq -sRr @uri)&sort=updated&per_page=30" --jq '.items[].full_name'

**Example - Multi-language with exclusions:**
```bash
gh api "search/repositories?q=$(printf '%s' 'stars:>500 language:rust language:go language:TypeScript language:javascript -topic:ethereum -topic:cryptocurrency -topic:blockchain -topic:bitcoin -topic:web3' | jq -sRr @uri)&sort=updated&per_page=10" --jq '.items[].full_name'
Why use this?
  • gh search repos
    is a convenience wrapper with its own query parsing
  • gh api search/repositories
    hits the raw API, matching web behavior exactly
  • Required when combining: multiple languages + topic exclusions + star filters
Common jq extractions:
Outputjq filter
Names only
--jq '.items[].name'
Full names
--jq '.items[].full_name'
With stars
--jq '.items[] | "\(.full_name) ⭐\(.stargazers_count)"'
URLs
--jq '.items[].html_url'
Full JSON(omit --jq)
gh api "search/repositories?q=$(printf '%s' 'YOUR_QUERY_HERE' | jq -sRr @uri)&sort=updated&per_page=30" --jq '.items[].full_name'

**示例 - 多语言并排除指定主题:**
```bash
gh api "search/repositories?q=$(printf '%s' 'stars:>500 language:rust language:go language:TypeScript language:javascript -topic:ethereum -topic:cryptocurrency -topic:blockchain -topic:bitcoin -topic:web3' | jq -sRr @uri)&sort=updated&per_page=10" --jq '.items[].full_name'
为什么使用该方式?
  • gh search repos
    是一个便捷的封装工具,有自己的查询解析逻辑
  • gh api search/repositories
    调用原生API,结果与网页端完全一致
  • 当需要组合多语言、主题排除和星标筛选时必须使用
常用jq提取方式:
输出内容jq过滤器
仅名称
--jq '.items[].name'
完整名称
--jq '.items[].full_name'
带星标数量
--jq '.items[] | "\(.full_name) ⭐\(.stargazers_count)"'
仓库URL
--jq '.items[].html_url'
完整JSON数据(省略--jq参数)

Patterns

使用模式

Finding Repositories

查找仓库

When you see: User wants to find projects/repos by criteria Use:
gh search repos
bash
undefined
适用场景: 用户希望根据条件查找项目/仓库 使用命令:
gh search repos
bash
undefined

Basic search with stars

带星标条件的基础搜索

gh search repos "stars:>500 language:rust" --sort=stars --limit=50
gh search repos "stars:>500 language:rust" --sort=stars --limit=50

Multiple languages (OR logic)

多语言搜索(或逻辑)

gh search repos "language:rust language:go language:typescript"
gh search repos "language:rust language:go language:typescript"

Exclude topics

排除指定主题

gh search repos "stars:>1000 -topic:cryptocurrency -topic:blockchain"
gh search repos "stars:>1000 -topic:cryptocurrency -topic:blockchain"

By topic

按主题搜索

gh search repos "topic:cli topic:terminal stars:>100"
gh search repos "topic:cli topic:terminal stars:>100"

Recently updated

查找近期更新的仓库

gh search repos "language:python pushed:>2024-01-01"

**Output formats:**
```bash
--json name,url,description,stargazersCount  # JSON output
--web                                         # Open in browser
gh search repos "language:python pushed:>2024-01-01"

**输出格式:**
```bash
--json name,url,description,stargazersCount  # JSON格式输出指定字段
--web                                         # 在浏览器中打开结果

Finding Code Examples

查找代码示例

When you see: User wants to know how to use a library Use:
gh search code
bash
undefined
适用场景: 用户希望了解某个库的使用方式 使用命令:
gh search code
bash
undefined

Find usage patterns

查找使用模式

gh search code "from zod import" --limit=20 gh search code "import { z } from 'zod'" --limit=20
gh search code "from zod import" --limit=20 gh search code "import { z } from 'zod'" --limit=20

In specific file types

按文件类型搜索

gh search code "useQuery" extension:tsx --limit=30
gh search code "useQuery" extension:tsx --limit=30

In specific paths

按文件路径搜索

gh search code "tanstack/query" path:src/ extension:ts
gh search code "tanstack/query" path:src/ extension:ts

Exact phrase

精确短语搜索

gh search code '"createTRPCRouter"' extension:ts

**Pro tip:** Combine with repo filter for focused results:
```bash
gh search code "pattern" repo:owner/repo
gh search code '"createTRPCRouter"' extension:ts

**专业提示:** 结合仓库过滤器获取精准结果:
```bash
gh search code "pattern" repo:owner/repo

Finding Issues/Discussions

查找议题/讨论

When you see: User looking for bug reports, feature requests, or discussions Use:
gh search issues
or
gh search prs
bash
undefined
适用场景: 用户查找bug报告、功能请求或讨论内容 使用命令:
gh search issues
gh search prs
bash
undefined

Open issues with label

查找指定仓库的带bug标签的开放议题

gh search issues "is:open label:bug repo:facebook/react"
gh search issues "is:open label:bug repo:facebook/react"

PRs by author

查找指定作者的已合并拉取请求

gh search prs "author:username is:merged"
gh search prs "author:username is:merged"

Issues mentioning error

查找提及特定错误的Go语言相关议题

gh search issues '"connection refused" language:go'
undefined
gh search issues '"connection refused" language:go'
undefined

Query Qualifiers Reference

查询限定符参考

Repo Search

仓库搜索

QualifierExampleDescription
stars:
stars:>1000
,
stars:100..500
Star count
forks:
forks:>100
Fork count
language:
language:rust
Primary language
topic:
topic:cli
Repository topic
-topic:
-topic:blockchain
Exclude topic
pushed:
pushed:>2024-01-01
Last push date
created:
created:>2023-01-01
Creation date
license:
license:mit
License type
archived:
archived:false
Archive status
is:
is:public
,
is:private
Visibility
限定符示例说明
stars:
stars:>1000
,
stars:100..500
星标数量
forks:
forks:>100
复刻数量
language:
language:rust
仓库主语言
topic:
topic:cli
仓库主题
-topic:
-topic:blockchain
排除指定主题
pushed:
pushed:>2024-01-01
最后推送日期
created:
created:>2023-01-01
仓库创建日期
license:
license:mit
许可证类型
archived:
archived:false
归档状态
is:
is:public
,
is:private
仓库可见性

Code Search

代码搜索

QualifierExampleDescription
extension:
extension:ts
File extension
path:
path:src/
File path
repo:
repo:owner/name
Specific repo
language:
language:javascript
Code language
filename:
filename:package.json
File name
限定符示例说明
extension:
extension:ts
文件扩展名
path:
path:src/
文件路径
repo:
repo:owner/name
指定仓库
language:
language:javascript
代码语言
filename:
filename:package.json
文件名

Common Flags

常用参数

FlagDescription
--limit N
Number of results (max 1000)
--sort X
Sort by: stars, forks, updated, best-match
--order X
asc or desc
--json FIELDS
JSON output with specific fields
--web
Open results in browser
参数说明
--limit N
结果数量上限(最大1000)
--sort X
排序依据:stars、forks、updated、best-match
--order X
排序顺序:升序(asc)或降序(desc)
--json FIELDS
以JSON格式输出指定字段
--web
在浏览器中打开结果

Common Use Cases

常见使用场景

"Find popular X repos"

查找热门X语言仓库

bash
gh search repos "language:X stars:>500" --sort=stars --limit=50
bash
gh search repos "language:X stars:>500" --sort=stars --limit=50

"How do people use library Y"

了解人们如何使用库Y

bash
gh search code "import Y" extension:ts --limit=30
gh search code "from Y import" extension:py --limit=30
bash
gh search code "import Y" extension:ts --limit=30
gh search code "from Y import" extension:py --limit=30

"Find repos like Z but exclude crypto"

查找类似Z的仓库但排除加密货币相关

bash
gh search repos "topic:Z -topic:cryptocurrency -topic:blockchain -topic:web3"
bash
gh search repos "topic:Z -topic:cryptocurrency -topic:blockchain -topic:web3"

"Find recent active projects"

查找近期活跃的项目

bash
gh search repos "language:go pushed:>2024-06-01 stars:>100" --sort=updated
bash
gh search repos "language:go pushed:>2024-06-01 stars:>100" --sort=updated

Tips

小贴士

  1. Quote the query when it contains special chars:
    gh search repos "stars:>500"
  2. Multiple languages = OR:
    language:rust language:go
    matches either
  3. Use
    --json
    for scripting:
    --json name,url,stargazersCount
  4. Date ranges:
    pushed:2024-01-01..2024-06-01
  5. Numeric ranges:
    stars:100..500
  6. Use
    gh api
    for complex queries
    : When
    gh search repos
    gives unexpected results, use
    gh api search/repositories?q=...
    for exact web parity
  1. 当查询包含特殊字符时,请给查询内容加引号:
    gh search repos "stars:>500"
  2. 多语言表示“或”逻辑:
    language:rust language:go
    会匹配任意一种语言的仓库
  3. 编写脚本时使用
    --json
    参数:
    --json name,url,stargazersCount
  4. 日期范围:
    pushed:2024-01-01..2024-06-01
  5. 数值范围:
    stars:100..500
  6. 复杂查询使用
    gh api
    :当
    gh search repos
    结果不符合预期时,使用
    gh api search/repositories?q=...
    获取与网页端完全一致的结果