---
title: "Search"
description: "Search repository contents, filenames, commit messages, and diffs."
url: "/docs/git/search"
---

Freestyle Git search lets your product inspect code without cloning a repository.


## Content Search

Search file contents at a branch, tag, or commit.

```ts TypeScript
import { freestyle } from "freestyle";

const repo = freestyle.git.repos.ref({ repoId: "your-repo-id" });

const result = await repo.search({
query: "TODO",
rev: "main",
pathPattern: "src/**/\*.ts",
excludePattern: "**/\*.test.ts"
});

for (const file of result.files) {
for (const match of file.matches) {
console.log(`${file.path}:${match.lineNumber} ${match.line}`);
}
}

````

```bash cURL
curl "https://api.freestyle.sh/git/v1/repo/${REPO_ID}/search?query=TODO&pathPattern=src/**/*.ts" \
  -H "Authorization: Bearer ${FREESTYLE_API_KEY}"
````

Use regex patterns when you need structural matches:

```ts
const result = await repo.search({
  query: "^(export\\s+)?(async\\s+)?function\\s+\\w+",
  isRegex: true,
  pathPattern: "**/*.ts",
});
```


## Filename Search

```ts
const result = await repo.searchFiles({
  query: "index",
  maxResults: 20,
});

for (const file of result.files) {
  console.log(file.path);
}
```


## Commit Message Search

```ts
const result = await repo.searchCommits({
  query: "fix",
  maxResults: 10,
});

for (const commit of result.commits) {
  console.log(`${commit.sha.slice(0, 7)} ${commit.message}`);
}
```


## Diff Search

Use diff search when you need to find when text was added or changed.

```ts
const result = await repo.searchDiffs({
  query: "deprecatedMethod",
  maxResults: 20,
});

for (const match of result.matches) {
  console.log(match.commitSha, match.filePath);
}
```


## Pagination

Use `maxResults`, `offset`, and `hasMore` to page through large result sets.

```ts
let offset = 0;
const files = [];

while (true) {
  const result = await repo.search({
    query: "TODO",
    maxResults: 50,
    offset,
  });

  files.push(...result.files);

  if (!result.hasMore) break;
  offset += 50;
}
```
