# find_git_common_dir

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/_git/find_git_common_dir)

Resolve a validated identity shared by one repository's Git worktrees.

A normal checkout uses its in-tree `.git` directory. A linked worktree is
accepted only when its administration directory lives directly under the
common repository's `worktrees` directory and its `gitdir` file points back
to the current worktree's `.git` file, and both the shared common directory
and the worktree's own administration directory carry valid repository
metadata (`_is_valid_git_common_dir` plus the worktree's own `HEAD`). These
checks prevent a forged pointer or directory link from borrowing another
repository's identity.

## Signature

```python
find_git_common_dir(
    path: str | Path,
) -> Path | None
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `path` | `str \| Path` | Yes | Exact working-tree root or persisted common-directory path. |

## Returns

`Path | None`

The canonical Git common directory, or `None` when the metadata cannot

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/caaa7e7c12d214afa5cf0a1afed8eb6232aa6f7b/libs/code/deepagents_code/_git.py#L276)