Search code at a ref
searchFind text in a GitLab file tree at any branch, tag, or commit without cloning; results group matches by file and can list paths or hit counts.
Instructions
Search a whole file tree at a branch, tag, or commit — git grep — without cloning it into a working tree. Matches come back grouped by file: the path, then line: text for each hit. Set output to files or count when you want to know which files, or how many hits each holds, rather than read the lines: those two ask git not to emit a matched line at all, so they stay cheap and their totals stay exact on a broad query. Matching is literal (foo|bar matches that text, not foo or bar) and case-insensitive unless you say otherwise; the ref defaults to the repository's default branch. The ref is resolved before searching, so a branch created moments ago is fetched on the miss, and the result states the commit it searched and synced_at. path is a git pathspec, passed through as git defines it: src/components/*.tsx works, but a plain pathspec's ** needs at least one directory level — use :(glob)src/**/*.tsx for zero or more. A path that matches nothing simply returns no matches. Pass context to see the lines around each match: the hunk is numbered and matched lines are marked >, which git's own context flags cannot do here — under -z they lose which line matched. Use pickaxe to find when the text appeared.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ref | No | Branch, tag, or commit to search, e.g. 'fix/PROJ-7608'. Defaults to the default branch. | |
| path | No | A git pathspec to limit the search, e.g. 'src/components/*.tsx'. Use ':(glob)src/**/*.tsx' for `**` to match zero or more directories, which a plain pathspec does not do. | |
| query | Yes | Text to look for, e.g. 'vehicleCount'. Literal unless `regex` is set. | |
| regex | No | Treat `query` as a POSIX extended regex (not PCRE). Default false: match it literally. | |
| output | No | What to return. Default 'matches': the matching lines, grouped by file. 'files': just the paths that matched. 'count': the path and matching-line count per file, with an exact 'total'. The last two skip emitting matched lines, so they are cheaper and stay exact on a broad query. | |
| context | No | Lines to show on each side of every match (default 0, none), marked so a matched line is distinguishable from a nearby one. Built by reading each displayed file once — at most 20 files per call — because git's own context flags lose which line matched under -z. Needs output 'matches'. | |
| project | No | GitLab project path, e.g. 'group/subgroup/repo'. Defaults to GITLAB_DEFAULT_PROJECT. | |
| max_matches | No | Maximum rows to return (default 100): matches, or files in the other modes. Tops them out; the totals in the header stay exact. | |
| case_sensitive | No | Match case exactly. Default false: search ignores case. |