Repositories

Search code

Search the files of one branch or tag in a repository. Open the Search tab in the repository header, or /<owner>/<repo>/search.

Search in the browser

Type a pattern; results update as you type. The ref switcher picks the branch or tag (the default branch unless you change it). Two toggles sit beside the box:

  • Aa: ignore letter case.
  • .*: treat the pattern as a regular expression, written in JavaScript syntax (see Regular expressions).

Results are grouped by file, with three lines of context around each match. Select the file name to open the file, or a line number to jump to that line. The address keeps your query and ref, so you can share the results.

Search from the CLI

sh
1cafe repo code search TODO --repo owner/repo --path src

--path limits the search to a file or directory (--path src includes src/main.ts but not src-other/main.ts). --regex and --ignore-case match the browser toggles, and --ref picks the branch or tag.

Regular expressions

Patterns are matched one line at a time by an RE2 engine, whose time grows only linearly with the line, so no pattern can stall a search. They are written as JavaScript regular expressions, with these differences:

  • Lookahead ((?=…), (?!…)) and backreferences (\1, \k<name>) are not supported; the search reports the pattern as invalid. Lookbehind works, but not with a capturing group inside it.
  • \s matches ASCII whitespace only, and . also matches a carriage return.
  • RE2 syntax JavaScript lacks also works, such as (?i) and \pL.

Limits

  • Only the files of the selected ref are searched, not history, commit messages, issues or pull requests.
  • At most 100 matches are returned; the page says Results truncated when there are more. Narrow the pattern or the path.
  • Regular-expression searches stop after 5,000 tree entries, 32 MiB of content or 4 seconds. Binary files and files over 1 MiB are skipped. A line too long for a complex pattern to match in time is skipped too, and the page then says Results truncated.
  • Context lines are shown for the first 50 matching files.
Read as MarkdownGitCafe documentation
Documentation