> ## Documentation Index
> Fetch the complete documentation index at: https://sourcebot-msukkarieh-ado.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Local Git repositories

Sourcebot can sync code from generic git repositories stored in a local directory. This can be helpful in scenarios where you already have a large number of repos already checked out. Local repositories are treated as **read-only**, meaning Sourcebot will **not** `git fetch` new revisions.

If you're not familiar with Sourcebot [connections](/docs/connections/overview), please read that overview first.

## Getting Started

<Warning>
  Only folders containing git repositories at their root **and** have a `remote.origin.url` set in their git config are supported at this time. All other folders will be skipped.
</Warning>

Let's assume we have a `repos` directory located at `$(PWD)` with a collection of git repositories:

```sh
repos/
├─ repo_1/
├─ repo_2/
├─ repo_3/
├─ ...
```

To get Sourcebot to index these repositories:

<Steps>
  <Step title="Mount a volume">
    We need to mount a docker volume to the `repos` directory so Sourcebot can read it's contents. Sourcebot will **not** write to local repositories, so we can mount a separate **read-only** volume:

    ```bash
    docker run \
        -v $(pwd)/repos:/repos:ro \
        /* additional args */ \
        ghcr.io/sourcebot-dev/sourcebot:latest
    ```
  </Step>

  <Step title="Create a connection">
    We can now create a new git [connection](/docs/connections/overview), specifying local paths with the `file://` prefix. Glob patterns are supported. For example:

    ```json
    {
        "type": "git",
        "url": "file:///repos/*"
    }
    ```

    Sourcebot will expand this glob pattern into paths `/repos/repo_1`, `/repos/repo_2`, etc. and index all valid git repositories.
  </Step>
</Steps>

## Examples

<AccordionGroup>
  <Accordion title="Sync individual repo">
    ```json
    {
        "type": "git",
        "url": "file:///path/to/git_repo"
    }
    ```
  </Accordion>

  <Accordion title="Sync multiple repos using glob patterns">
    ```json
    // Attempt to sync directories contained in `repos/` (non-recursive)
    {
        "type": "git",
        "url": "file:///repos/*"
    }
    ```
  </Accordion>
</AccordionGroup>

## Schema reference

<Accordion title="Reference">
  [schemas/v3/genericGitHost.json](https://github.com/sourcebot-dev/sourcebot/blob/main/schemas/v3/genericGitHost.json)

  {/* THIS IS A AUTO-GENERATED FILE. DO NOT MODIFY MANUALLY! */}

  ```json
  {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "title": "GenericGitHostConnectionConfig",
    "properties": {
      "type": {
        "const": "git",
        "description": "Generic Git host configuration"
      },
      "url": {
        "type": "string",
        "format": "url",
        "description": "The URL to the git repository. This can either be a remote URL (prefixed with `http://` or `https://`) or a absolute path to a directory on the local machine (prefixed with `file://`). If a local directory is specified, it must point to the root of a git repository. Local directories are treated as read-only modified. Local directories support glob patterns.",
        "pattern": "^(https?:\\/\\/[^\\s/$.?#].[^\\s]*|file:\\/\\/\\/[^\\s]+)$",
        "examples": [
          "https://github.com/sourcebot-dev/sourcebot",
          "file:///path/to/repo",
          "file:///repos/*"
        ]
      },
      "revisions": {
        "type": "object",
        "description": "The revisions (branches, tags) that should be included when indexing. The default branch (HEAD) is always indexed. A maximum of 64 revisions can be indexed, with any additional revisions being ignored.",
        "properties": {
          "branches": {
            "type": "array",
            "description": "List of branches to include when indexing. For a given repo, only the branches that exist on the repo's remote *and* match at least one of the provided `branches` will be indexed. The default branch (HEAD) is always indexed. Glob patterns are supported. A maximum of 64 branches can be indexed, with any additional branches being ignored.",
            "items": {
              "type": "string"
            },
            "examples": [
              [
                "main",
                "release/*"
              ],
              [
                "**"
              ]
            ],
            "default": []
          },
          "tags": {
            "type": "array",
            "description": "List of tags to include when indexing. For a given repo, only the tags that exist on the repo's remote *and* match at least one of the provided `tags` will be indexed. Glob patterns are supported. A maximum of 64 tags can be indexed, with any additional tags being ignored.",
            "items": {
              "type": "string"
            },
            "examples": [
              [
                "latest",
                "v2.*.*"
              ],
              [
                "**"
              ]
            ],
            "default": []
          }
        },
        "additionalProperties": false
      }
    },
    "required": [
      "type",
      "url"
    ],
    "additionalProperties": false
  }
  ```
</Accordion>
