Code Search is available on Enterprise Starter and Enterprise plans, and through the VS Code and JetBrains editor extensions.
Why Code Search
Large organizations accumulate code across dozens of code hosts, hundreds of repositories, and thousands of branches. Traditional tools search one repository at a time. Sourcegraph Code Search operates across your entire connected codebase simultaneously:- Search all repositories on GitHub, GitLab, Bitbucket, Gerrit, and more from a single query
- Search any branch or commit, not just the default branch
- Results are always up to date—Sourcegraph fetches repository contents on any user action and makes new commits available immediately
- Use regular expressions, boolean operators, and structural patterns to express precise queries
- Symbol, diff, and commit search let you understand how code has changed over time
Supported code hosts
Code Search works with all major code hosts:GitHub & GitHub Enterprise
Search public and private repositories hosted on GitHub.com or a self-hosted GitHub Enterprise instance.
GitLab & GitLab Self-Managed
Search repositories on GitLab.com or your own GitLab instance.
Bitbucket Cloud & Server
Connect Bitbucket Cloud or Bitbucket Data Center repositories.
Gerrit
Search code reviewed and hosted on Gerrit.
Azure DevOps
Search repositories in Azure DevOps organizations.
Other Git hosts
Any Git-based host accessible over HTTPS or SSH can be connected.
Search types
Sourcegraph supports three search modes. You can switch between them using the toggle buttons in the search bar or by specifyingpatternType: in the query.
- Keyword (default)
- Regular expression
- Structural
Keyword search matches individual terms anywhere in the document or filename. Terms are matched independently; Keyword search replaced
foo bar finds files containing both foo and bar anywhere.Use double quotes to match a phrase exactly: "foo bar" matches only when the words appear together in that order.Embed a regular expression inside /... to mix literal terms with regex in the same query:standard as the default pattern type in Sourcegraph 5.4.Running your first search
Open the search bar
Navigate to your Sourcegraph instance. The search bar is on the home page and at the top of every page.
Enter a query
Type a term, phrase, or pattern. For example, to find all uses of
http.NewRequest in Go files:Refine with filters
Add filters to narrow results by repository, file path, language, author, or time. Filters can be combined freely:
Key capabilities
Search across branches and commits
Search across branches and commits
By default, Sourcegraph searches the HEAD of the default branch. Use Search multiple revisions at once by separating them with
rev: or append @revision to the repo: filter to search any branch, tag, or commit hash:::Commit diff and message search
Commit diff and message search
Find code changes over time with
type:diff, or search commit messages with type:commit. Filter by author, date range, and commit message content:Symbol search
Symbol search
Search for functions, classes, variables, and other symbols directly with
type:symbol. Symbol results also appear in the typeahead as you type, letting you jump straight to a definition:Search contexts
Search contexts
Search contexts let you scope searches to a defined set of repositories and revisions. Use predefined contexts like
context:global, or create your own to target a specific team’s repos or a release branch across multiple repositories:Saved searches
Saved searches
Save any query to reuse it and monitor its results on an ongoing basis. Saved searches are useful for tracking known problem patterns, monitoring best-practice compliance, or watching the progress of a refactor.
Explore further
Query syntax
Complete reference for all filters, boolean operators, regex patterns, and structural search syntax.
Features
In-depth docs on saved searches, search contexts, code monitoring, symbol search, and more.
Cody AI
Use Cody to understand code, generate explanations, and get AI-assisted answers grounded in your codebase.
Stream API
Integrate Code Search results into your own tools using the streaming search API.