> ## Documentation Index
> Fetch the complete documentation index at: https://code.storage/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# repo.getBranchDiff()

> Get the diff between a branch and its base.

> [!WARNING]
>
> This page documents the earlier Code Storage SDKs: `@pierre/storage`, `pierre-storage`, and
> `code-storage-go`. New code uses the [Pierre SDK](https://code.storage/docs/sdks.md). To move code to the new SDK, use the
> [`pierre-migrate`
> skill](https://github.com/pierrecomputer/skills/tree/main/skills/pierre-migrate).

```typescript TypeScript theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
// Compare feature branch to main
const diff = await repo.getBranchDiff({
  branch: 'feature/new-auth',
  base: 'main', // optional, defaults to default branch
});

console.log(`Changed files: ${diff.stats.files}`);
console.log(`+${diff.stats.additions} -${diff.stats.deletions}`);

diff.files.forEach((file) => {
  if (file.state === 'renamed') {
    console.log(`Renamed: ${file.oldPath} -> ${file.path} (${file.rawState})`);
  }
});

// Filter to specific files
const filteredDiff = await repo.getBranchDiff({
  branch: 'feature/new-auth',
  paths: ['src/auth.ts', 'src/utils/token.ts'],
});
```

```python Python theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
branch_diff = await repo.get_branch_diff(
    branch="feature/new-auth",
    base="main",  # optional, defaults to main
)
print(branch_diff["stats"])
print(branch_diff["files"])
for file in branch_diff["files"]:
    if file["state"] == "renamed":
        print(f"Renamed: {file['oldPath']} -> {file['path']} ({file['rawState']})")

# Filter to specific files
filtered_diff = await repo.get_branch_diff(
    branch="feature/new-auth",
    paths=["src/auth.py", "src/utils/token.py"],
)
```

```go Go theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
// Compare a branch to main
diff, err := repo.GetBranchDiff(context.Background(), storage.GetBranchDiffOptions{
	Branch: "feature/new-auth",
	Base:   "main",
})
fmt.Printf("Changed files: %d", diff.Stats.Files)

// Filter to specific files
filtered, err := repo.GetBranchDiff(context.Background(), storage.GetBranchDiffOptions{
	Branch: "feature/new-auth",
	Paths:  []string{"src/auth.go", "src/utils/token.go"},
})
```

## Options

**branch** `string` *required*

The branch name to get the diff for

**base** `string`

Base branch to compare against (defaults to repository's default branch)

**ephemeral** `string`

When `true`, resolves the branch under the ephemeral namespace

**ephemeralBase** `string`

When `true`, resolves the base branch under the ephemeral namespace

**paths** `string`

Array of file paths to filter the diff. When provided, only returns diffs for the specified files
and bypasses size/type filtering

## Response

**stats** `object`

Summary with `files`, `additions`, `deletions`, and `changes`

**files** `array`

List of changed files with `path`, `oldPath`, `state`, `rawState`, and diff content

## Notes

* For renamed files, `path` is the new location and `oldPath` is the previous location
* `state` is normalized to `renamed`, while `rawState` preserves Git's original rename code (for
  example `R054`, where `054` is the similarity score)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.