How to Search Code Across Repos With Sourcegraph

October 16, 2026

Sourcegraph is a code search and intelligence platform that indexes many repositories at once. Instead of cloning each repo, you search all of them from one query box, using regex or structural patterns that understand code rather than just matching text.

You can use the free public index at sourcegraph.com or self-host. This guide covers both, plus the query syntax that makes it worth switching from grep.

What can Sourcegraph find that grep cannot?

Three things. It searches across repos without cloning. It understands code structure, so you can match a function call with any arguments. And it handles languages across thousands of repos with results ranked by relevance. The Sourcegraph query language supports filters like lang:, repo: and file: that narrow results instantly.

How do I run my first search?

  1. Go to sourcegraph.com/search. No account needed for public repos.
  2. Type a plain query, e.g. context.WithTimeout.
  3. Add filters: lang:go repo:github.com/gorilla.
  4. Switch to the Code Search tab and enable regex for pattern matching.

For structural matching, wrap the pattern in a patternType:structural search — for example finding every call of a function regardless of arguments.

How do I search my own private repos?

You need either a cloud account with connected repos, or a self-hosted instance. Self-hosting runs a Sourcegraph container stack and indexes your code locally.

docker run --publish 7080:7080 --publish 3379:3379 sourcegraph/server:latest

External services (GitHub, GitLab, Bitbucket) are added as connections, then Sourcegraph indexes them. Fair warning: for large codebases the first index takes hours and needs real disk and RAM. Check the sizing docs before committing.

Is Sourcegraph free?

There is a free tier for public code search, and Sourcegraph offers a free plan for individual developers that includes some private repo indexing. Enterprise features — fine-grained permissions, SSO, large-scale self-hosting support — are paid and priced per user. The exact numbers change, so confirm on their pricing page; the free code-search-for-public-repos capability has no time limit.

Where does Sourcegraph not shine?

It is a search tool, not an IDE. There is no refactoring, no run button, and editing is minimal. Indexing lag also means very recent commits can take a while to appear. And if you only work in one small repo, plain ripgrep with a good editor is less overhead — Sourcegraph pays off at scale, when “which repos use this old API?” becomes a daily question.

Quick Summary

  • Sourcegraph searches code across many repos at once with regex and structural queries.
  • Public search is free at sourcegraph.com; self-host via Docker for private code.
  • Filters like lang:, repo:, file: make queries precise.
  • Strong for cross-repo questions; not an editor and heavy to self-host at scale.