Sourcegraph search query language

This page provides a visual breakdown of our Search Query Language and a handfulof examples to get you started. It is complementary to our syntax reference and illustrates syntax using railroad diagrams instead oftables.

How to read railroad diagrams. Follow the lines in these railroad diagrams to seehow pieces of syntax combine. When a line splits it means there are multiple optionsavailable. When it is possible to repeat a previous syntax, the split line will loop backon itself like this:

Basic query

At a basic level, a query consists of search patterns and parameters. Typical queries contain one or more space-separated search patterns that describe what to search, and parameters refine searches by filtering results or changing search behavior.

Example: file:schema.graphql The result


Build query expressions by combining basic queries and operators like AND or OR.Group expressions with parentheses to build more complex expressions. If there are no balanced parentheses, AND operators bind tighter, so foo or bar and baz means foo or (bar and baz). You may also use lowercase and or or.

Example: rtr AND newRouter

Search pattern

A pattern to search. By default the pattern is searched literally. The kind of search may be toggled to change how a pattern matches:

  • Perform a [regular expression search]( We support [RE2 syntax]( Quoting patterns performs a literal search.
    Example: foo.*bar.*baz "foo bar"
  • Perform a structural search. See our [dedicated documentation]( to learn more about structural sexarch.
    Example: fmt.Sprintf(":[format]", :[args])


Search parameters allow you to filter search results or modify search behavior.


Search repositories that match the regular expression. A - before repo excludes the repository. By default the repository will be searched at theHEAD commit of the default branch. You can optionally change therevision.

Example: repo:gorilla/mux testroute-repo:gorilla/mux testroute


Search a repository at a given revision. For example, a branch name, commit hash, or git tag.

Example: repo:^github\.com/gorilla/[email protected] testroute or repo:^github\.com/gorilla/mux$ rev:v1.8.0 testroute

You can search multiple revisions by separating the revisions with :. Specify HEAD for the default branch.

Example: repo:^github\.com/gorilla/[email protected]:v1.4.0 testing.T or repo:^github\.com/gorilla/mux$ rev:v1.7.4:v1.4.0 testing.T


Search files whose full path matches the regular expression. A - before file excludes the file from being searched.

Example: file:\.js$ httptestfile:\.js$ -file:test http


Only search files in the specified programming language, like typescript orpython.

Example: lang:typescript encoding


Set the search pattern to search using a dedicated parameter. Useful, forexample, when searching literally for a string like repo:my-repo that mayconflict with the syntax of parameters in this Sourcegraph language.

Example: repo:sourcegraph content:"repo:sourcegraph"


Selects the specified result type from the set of search results. If a query produces results that aren't of theselected type, the results will be converted to the selected type.

For example, the query file:package.json lodash will return content matches for lodash in package.json files.If select:repo is added, the repository those matches belong to is pulled out and it now only returnsrepositories that contain package.json files that contain the term lodash. All selected results are deduplicated,so if there are multiple content matches in a repository, select:repo will still only return unique results.

A query like type:commit example select:symbol will return no results because commits have no associated symboland cannot be converted to that type.

Example: fmt.Errorf select:repo zoektSearch select:file

Symbol kind

Select a specific kind of symbol. For example type:symbol select:symbol.function zoektSearch will only return functions that contain theliteral zoektSearch.

Example: type:symbol zoektSearch select:symbol.function

Modified lines

When searching commit diffs, select only diffs where the pattern matches onadded (respectively, removed) lines. For example, search for recent commitsthat removed TODOs in your code.

- Note: if any line exists that satisfies the condition, the entire diff is included in the result set.
- Note: type:diff must be specified in the query.


repo:^github\.com/sourcegraph/sourcegraph$ type:diff TODO select:commit.diff.removed

File kind

Select only directory paths of file results with This is useful for discovering the directory paths that specify a package.json file, for returns the full path for the file and is equivalent to select:file. It exists as a fully-qualified alternative.

Example: file:package\.json


Set whether the search pattern should perform a search of a certain type.Notable search types are symbol, commit, and diff searches.

Example: type:symbol pathtype:commit author:nick


Set whether the search pattern should be treated case-sensitively. This issynonymous with the toggle button.

Example: OPEN_FILE case:yes


Set to yes if repository forks should be included or only if only forksshould be searched. Repository forks are excluded by default.

Example: fork:yes repo:sourcegraph


Set to yes if archived repositories should be included or only if onlyarchives should be searched. Archived repositories are excluded by default.

Example: archived:only repo:sourcegraph

Repo group

Only include results from the named group of repositories (defined by the serveradmin). Same as using repo that matches all of the group’srepositories. Use repo unless you know that the groupexists.

Example: repogroup:go-gh-100 helm  – searches the top 100 Go repositories on GitHub, ranked by stars.

Repo has file

Deprecated. Prefer Repo contains file. Only include results from repositories that contain a matching file. Thiskeyword is a pure filter, so it requires at least one other search term in thequery. Note: this filter currently only works on text matches and file pathmatches.

Example: repohasfile:\.py file:Dockerfile$ pip

Repo has commit after

Deprecated. Prefer Repo contains commit after. Filter out stale repositories that don’tcontain commits past the specified time frame. This parameter is experimental.

Example: repo:github\.com/sourcegraph repohascommitafter:"1 week ago"


Retrieve N results. By default, Sourcegraph stops searching early andreturns if it finds a full page of results. This is desirable for mostinteractive searches. To wait for all results, use count:all.

Example: count:1000 function count:all err


Set a search timeout. The time value is a string like 10s or 100ms, which isparsed by the Go timepackage's ParseDuration.By default the timeout is set to 10 seconds, and the search will optimize forreturning results as soon as possible. The timeout value cannot be set longerthan 1 minute.

Example: timeout:15s count:10000 func  – sets a longer timeout for a search that contains a lot of results.


Filter results to only public or private repositories. The default is to includeboth private and public repositories.

Example: type:repo visibility:public

Pattern type

Set whether the pattern should run a literal search, regular expression search,or a structural search pattern. This parameter is available as a command-line andaccessibility option, and synonymous with the visual search pattern search pattern.

Built-in repo predicate

Repo contains file

Search only inside repositories that contain a file path matching the regular expression.

Example: repo:contains.file(README)

Repo contains content

Search only inside repositories that contain file content matching the regular expression.

Example: repo:contains.content(TODO)

Repo contains file and content

Search only inside repositories that contain a file matching the file: with content: filters.

Example: repo:contains(file:CHANGELOG content:fix)

Repo contains commit after

Search only inside repositories that contain a commit after some specifiedtime. See git date formats for accepted formats. Use this to filter out stale repositories that don’t containcommits past the specified time frame. This parameter is experimental.

Example: repo:contains.commit.after(1 month ago)

Repo dependencies

Search only inside dependencies of repositories matching the given [email protected]:a:b:c input.

Example: repo:dependencies(^github\.com/sourcegraph/[email protected]:3.35) count:all

Built-in file predicate

File contains content

Search only inside files that contain content matching the provided regexp pattern.

Example: file:contains(github\.com/sourcegraph/sourcegraph)

Regular expression

A string that is interpreted as a RE2 regular expression.


An unquoted string is any contiguous sequence of characters not containing whitespace.

Quoted string

Any string, including whitespace, may be quoted with single ' or double " quotes. Quotes can be escaped with \. Literal \ characters will need to be escaped, e.g., \\.

Commit parameter

Set parameters that apply only to commit and diff searches.


Include commits or diffs that are authored by the user.


Include results which have a commit date before the specified time frame.Many forms are accepted for the argument, such as:

  • november 1 2019
  • 1 november 2019
  • 2019.11.1
  • 11/1/2019
  • 01.11.2019
  • Thu, 07 Apr 2005 22:13:13 +0200
  • 2005-04-07
  • 2005-04-07T22:13:13
  • 2005-04-07T22:13:13+07:00
  • yesterday
  • 5 days ago
  • 20 minutes ago
  • 2 weeks ago
  • 3:00
  • 3pm
  • 1632782809
  • 1632782809 -0600

Example: before:"last thursday"before:"november 1 2019"


Include results which have a commit date after the specified time frame.Many forms are accepted for the argument, such as:

  • november 1 2019
  • 1 november 2019
  • 2019.11.1
  • 11/1/2019
  • 01.11.2019
  • Thu, 07 Apr 2005 22:13:13 +0200
  • 2005-04-07
  • 2005-04-07T22:13:13
  • 2005-04-07T22:13:13+07:00
  • yesterday
  • 5 days ago
  • 20 minutes ago
  • 2 weeks ago
  • 3:00
  • 3pm
  • 1632782809
  • 1632782809 -0600

Example: after:"6 weeks ago"after:"november 1 2019"


Include results which have commit messages containing the string.

Example: type:commit message:"testing"