Skip to main content
Code Search lets you find, navigate, and understand code across all your repositories and code hosts in real time. Whether you’re tracking down a bug, auditing API usage, or understanding an unfamiliar codebase, Code Search gives you the query power to find exactly what you need—without cloning repos or waiting for indexing.
Code Search is available on Enterprise Starter and Enterprise plans, and through the VS Code and JetBrains editor extensions.
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 specifying patternType: in the query.
Keyword search matches individual terms anywhere in the document or filename. Terms are matched independently; 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:
logger.Error /timeout|deadline/
Keyword search replaced standard as the default pattern type in Sourcegraph 5.4.
1

Open the search bar

Navigate to your Sourcegraph instance. The search bar is on the home page and at the top of every page.
2

Enter a query

Type a term, phrase, or pattern. For example, to find all uses of http.NewRequest in Go files:
http.NewRequest lang:go
3

Refine with filters

Add filters to narrow results by repository, file path, language, author, or time. Filters can be combined freely:
http.NewRequest lang:go repo:myorg/ -file:_test\.go
4

Explore result types

Switch from code results to commit diffs, commit messages, or symbols using type:diff, type:commit, or type:symbol.

Key capabilities

By default, Sourcegraph searches the HEAD of the default branch. Use rev: or append @revision to the repo: filter to search any branch, tag, or commit hash:
repo:^github\.com/myorg/[email protected] deprecatedFunction
Search multiple revisions at once by separating them with ::
repo:^github\.com/myorg/myrepo$ rev:v1.0:v2.0 configParser
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:
context:@myteam/backend-services DatabaseClient
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.

Build docs developers (and LLMs) love