Search examples

Below are examples that search repositories on, our open source code search solution for GitHub and GitLab. You can copy and adapt the following search queries for use on your company’s private instance.

See search query syntax reference.

Find private keys and GitHub access tokens checked in to code

(-----BEGIN [A-Z ]*PRIVATE KEY------)|(("gh|'gh)[pousr]_[A-Za-z0-9_]{16,}) patternType:regexp case:yes

Recent security-related changes on all branches

type:diff repo:@*refs/heads/ after:"5 days ago"

Admitted hacks and TODOs in app code

-file:\.(json|md|txt)$ hack|todo|kludge|fixme

Removal of TODOs in the repository commit log

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

New usages of a function

type:diff after:"1 week ago" \.subscribe\( lang:typescript

Find multiple terms in the same file, like testing of HTTP components

repo:github\.com/sourcegraph/sourcegraph$ (test AND http AND NewRequest) lang:go

Recent quality related changes on all branches (customize for your linters)

repo:@*refs/heads/:^master type:diff after:"1 week ago" (eslint-disable)

Recent dependency changes

file:package.json type:diff after:"1 week ago"

Files that are Apache licensed

licensed to the apache software foundation select:file

Only repositories with recent dependency changes

file:package.json type:diff after:"1 week ago" select:repo

Search changes in a files that contain a keyword

repo:^github\.com/sourcegraph/sourcegraph$ type:diff file:contains.content("golang\.org/x/sync/errgroup") .Go

When to use regex search mode

Sourcegraph’s default literal search mode is line-based and will not match across lines, so regex can be useful when you wish to do so:

Matching multiple text strings in a file

repo:^github\.com/Parsely/pykafka$ Not leader for partition

Regex searches are also useful when searching boundaries that are not delimited by code structures:

Finding css classes with word boundary regex

repo:^github\.com/sourcegraph/sourcegraph$ \bbtn-secondary\b

When to use structural search mode

Use structural search when you want to match code boundaries such as () or {}:

Finding try catch statements with varying content

try { :[matched_statements] } catch { :[matched_catch] }