Search query syntax

Search queries can consist of just words, and you’ll see results where those words appear in order, in all files across all repositories. Many queries will also use keywords. Keywords help to filter searches, define the type of search, and more. This page is a comprehensive list of keywords available for code search.

Keywords (all searches)

The following keywords can be used on all searches:

Keyword Description Examples
regexp-pattern Plain words are actually interpreted as regular expressions (using the standard RE2 syntax). Multiple words are joined with \s* to construct the combined pattern. (open\|close)file
“any string” Surround a string in double quotes to find exact matches (including whitespace and punctuation). Use the \" and \\ escapes if needed. "system error 123"
repo:regexp-pattern

repo:[email protected]
Only include results from repositories whose path matches the regexp. A repository’s path is a string such as github.com/myteam/abc or code.example.com/xyz that depends on your organization’s repository host. If the regexp ends in @rev, that revision is searched instead of the default branch (usually master). repo:alice/abc
repo:alice/[email protected]
-repo:regexp-pattern Exclude results from repositories whose path matches the regexp. repo:alice/ -repo:alice/old-repo
repogroup:group-name Only include results from the named group of repositories (defined by the server admin). Same as using a repo: keyword that matches all of the group’s repositories. Use repo: unless you know that the group exists. repogroup:backend
file:regexp-pattern Only include results in files whose full path matches the regexp. file:\.js$
file:frontend/
-file:regexp-pattern Exclude results from files whose full path matches the regexp. file:\.js$ -file:test
-file:package.json
lang:language-name Only include results from files in the specified programming language. lang:typescript encoding
-lang:language-name Exclude results from files in the specified programming language. -lang:typescript encoding
count:N
max:N (deprecated alias)
Retrieve at least N results. By default, Sourcegraph stops searching early and returns if it finds a full page of results. This is desirable for most interactive searches. To wait for all results, or to see results beyond the first page, use the count: keyword with a larger N. This can also be used to get deterministic results and result ordering (whose order isn’t dependent on the variable time it takes to perform the search). count:1000 function
timeout:go-duration-value
Customizes the timeout for searches. The value of the parameter is a string that can be parsed by the Go time package’s ParseDuration (e.g. 10s, 100ms). By default, the timeout is set to 10 seconds, and the search will optimize for returning results as soon as possible. The timeout value cannot be set longer than 1 minute. When provided, the search is given the full timeout to complete. repo:^github.com/sourcegraph timeout:15s func count:10000
type:symbol Perform a symbol search. type:symbol path
case:yes Perform a case sensitive query. Without this, everything is matched case insensitively. OPEN_FILE case:yes
fork:no, fork:only Filter out results from repository forks or filter results to only repository forks. fork:no repo:^github\.com/[^/]*/go-langserver$ gendecl
archived:no, archived:only Filter out results from archived repositories or filter results to only archived repositories. By default, results from archived repositories are included. repo:sourcegraph/ archived:only

Multiple or combined repo: and file: keywords are intersected. For example, repo:foo repo:bar limits your search to repositories whose path contains both foo and bar (such as github.com/alice/foobar). To include results from repositories whose path contains either foo or bar, use repo:foo|bar.


Keywords (diff and commit searches only)

The following keywords are only used for commit diff and commit message searches, which show changes over time:

Keyword Description Examples
repo:[email protected] Specifies which Git refs (:-separated) to search for commits. Use *refs/heads/ to include all Git branches (and *refs/tags/ to include all Git tags). You can also prefix a Git ref name or pattern with ^ to exclude. For example, *refs/heads/:^refs/heads/master will match all commits that are not merged into master. repo:[email protected]*refs/heads/:^refs/heads/master
type:diff task
(unmerged commit diffs containing task)
type:diff
type:commit
Specifies the type of search. By default, searches are executed on all code at a given point in time (a branch or a commit). Specify the type: if you want to search over changes to code or commit messages instead (diffs or commits). type:diff
type:commit
author:name Only include results from diffs or commits authored by the user. Regexps are supported. Note that they match the whole author string of the form Full Name <[email protected]>, so to include only authors from a specific domain, use author:example.com>$.

You can also search by committer:git-email. Note: there is a committer only when they are a different user than the author.
author:[email protected]
author:git-email
before:“string specifying time frame” Only include results from diffs or commits which have a commit date before the specified time frame before:"last thursday"
before:"june 25 2017"
after:“string specifying time frame” Only include results from diffs or commits which have a commit date after the specified time frame after:"3 weeks ago"
after:"june 25 2017"
message:“any string” Only include results from diffs or commits which have commit messages containing the string type:commit message:"testing"
type:diff message:"testing"

A query with only repo: filters returns a list of repositories with matching names.

Example: repo:docker repo:registry

A query with type:path restricts terms to matching filenames only (not file contents).

Example: type:path repo:/docker/ registry