gh-search
Search GitHub repositories, issues, pull requests
TLDR
Search for code containing specific keywords
Search for issues with a specific phrase
Search commits by a specific author
Search pull requests assigned to yourself that are still open
Search repositories in an organization by topic
Search issues without a certain label (Unix-like systems)
Search issues without a certain label (PowerShell)
Open the search query in the web browser
SYNOPSIS
gh search <type> [flags]
where <type> is code, issues, repos, or users.
PARAMETERS
--author string
Author of the code, issue, PR, or commit
--assignee string
Assignee of the issue or PR
--base string
Base branch of the PR
--current-repo
Only search in the current repository
--filename string
Filename for code search
--head string
Head branch of the PR
--include-forks
Include forks in repository search
--jq string
Filter JSON output using a jq expression
--json strings
Output JSON with the specified fields
--label strings
Label of the issue or PR
--language string
Language of the repository or code
--limit int
Maximum number of items to fetch (default 30)
--match TITLE|DESCRIPTION|TEXT
Fields to match in (repeatable, default TITLE,DESCRIPTION)
--milestone int
Milestone number of the issue or PR
--order string
Order of results: asc, desc (default desc)
--org stringArray
Organizations to narrow the search
--owner string
Owner of the repo or author of the code
--path string
Path for code search
--repo string
Repository to search within
--size string
Size of the repository
--sort string
Sort field: bestmatch, stars, forks, help-wanted-issues, updated (default bestmatch)
--state string
State of issue/PR: open, closed, all (default open)
--stars string
Number of stars of the repository
--template string
Format JSON output using a Go template
--topic stringArray
Topics of the repository
--updated string
Updated time of the repository or code
DESCRIPTION
The gh search command is part of the GitHub CLI toolset, enabling powerful searches across GitHub's vast ecosystem directly from the terminal. It supports querying for code, repositories, issues (including pull requests), and users using GitHub's advanced search syntax combined with dedicated flags.
This tool leverages GitHub's Search API, allowing users to filter results by owner, language, labels, stars, updated dates, and more. For instance, developers can find specific code snippets, open issues with certain labels, popular repos by topic, or users by name. Results can be output in human-readable format, JSON for scripting, or custom templates.
Authentication via gh auth login is required for full access. It's ideal for CI/CD pipelines, quick lookups, or integrating into shell scripts. Unlike web searches, it provides structured, paginated output with precise control over sorting and limits, making it efficient for power users.
CAVEATS
Requires GitHub authentication (gh auth login). Subject to GitHub API rate limits (30 results default). Search syntax must follow GitHub conventions; complex queries may need URL-encoding in scripts.
SUPPORTED TYPES
code: Search code snippets.
issues: Issues and PRs.
repos: Repositories.
users: GitHub users.
EXAMPLES
gh search code --owner cli/cli hello
gh search issues --repo owner/repo label:bug
gh search repos topic:rust --limit 10 --json url,name
HISTORY
Introduced in GitHub CLI v0.6.0 (April 2020) as part of initial release features. Expanded in later versions (e.g., v2.0+) to include users type and enhanced flags. Actively maintained alongside CLI updates for new API capabilities.


