# Connect Your Repository

Connect your Git repository to enable version-controlled ML experiments. Valohai will fetch your code at the start of each execution and automatically track which commit was used.

## Before You Start

Make sure you have:

* A Valohai project (create one from the dashboard)
* A Git repository with your ML code
* (For private repos) SSH access configured

## Connect a Public Repository

Public repositories are the fastest way to get started—no authentication needed.

Navigate to your project settings:

1. Open your Valohai project
2. Go to **Settings** → **Repository**
3. Enter your repository URL in HTTPS format:

   ```
   https://github.com/username/repository.git
   ```
4. Click **Save**

Valohai will fetch your repository immediately. You'll see the available commits in the execution creation dialog.

## Connect a Private Repository

Private repositories require SSH authentication. Valohai uses deploy keys for secure, read-only access.

### Generate SSH Key in Valohai

The easiest method is to let Valohai generate the key pair:

1. Go to **Settings** → **Repository**
2. Click **Generate SSH Key**
3. Download or copy both keys:
   * Public key (`.pub`) – Add this to your Git provider
   * Private key (`.pem`) – Paste this into Valohai

### Add Public Key to Your Git Provider

The exact steps depend on your provider:

* [GitHub](/git-integration/private-repositories/github.md)
* [GitLab](/git-integration/private-repositories/gitlab.md)
* [Azure DevOps](/git-integration/private-repositories/azure-devops.md)
* [Bitbucket](/git-integration/private-repositories/bitbucket.md)

### Add Private Key to Valohai

Back in Valohai's repository settings:

1. Enter your SSH repository URL:

   ```
   git@github.com:username/repository.git
   ```
2. Paste the **entire private key** into the SSH private key field
3. The key should start with `-----BEGIN RSA PRIVATE KEY-----`
4. Click **Save**

Valohai will attempt to fetch the repository. If successful, you'll see your commits.

## Repository URL Formats

Use the correct URL format for your connection type:

**Public HTTPS repositories:**

```
https://github.com/username/repository.git
https://gitlab.com/username/repository.git
```

**Private SSH repositories:**

```
git@github.com:username/repository.git
git@gitlab.com:username/repository.git
git@ssh.dev.azure.com:v3/org/project/repository
git@bitbucket.org:username/repository.git
```

**Private HTTPS with credentials (not recommended):**

```
git+https://username:token@github.com/username/repository.git
```

> :bulb: **Use SSH for private repos.** Embedding credentials in URLs is less secure and harder to manage.

## Select branches

Using the **Branch** input field, select the branches you would like to track in Valohai. This setting requires a comma-separated list of branch names or patterns.

```
master, feature/*, experiment, release 
```

Selected branch patterns are compared against the existing branches using Shell Patterns.

```
*       matches everything
?       matches any single character
[seq]   matches any character in seq
[!seq]  matches any char not in seq
```

\
With each **Fetch repository** action, Valohai will fetch the latest commit from each of the selected branches.

> :bulb: To fetch [tags](https://git-scm.com/book/en/v2/Git-Basics-Tagging), add `tag/` prefix to your tag name, and as such add it to the **Branch** input field.
>
> ```
> master, tag/v0.1
> ```

## Verify the Connection

After connecting, verify everything works:

1. Go to **Executions** → **Create Execution**
2. Check the **Commit** dropdown—you should see your commits listed
3. If commits are missing, click **Fetch Repository** in settings

> :bulb: If you just connected the repository, no commits will appear in Valohai until you fetch it once.

## Fetch New Commits

Valohai caches your repository state. After pushing new commits, manually fetch to update:

1. Go to **Settings** → **Repository**
2. Click **Fetch Repository**
3. New commits appear immediately in execution dialogs

**Automate fetching with webhooks:**

* [GitHub Webhook Integration](/automation-overview/triggers/webhooks/examples/github-integration.md)

## Troubleshooting

**"Repository not found" or "Permission denied"**

* Double-check the repository URL format
* Ensure the SSH public key is added to your Git provider
* Verify the private key was pasted completely (including header/footer)

**"Fetch timeout" or "Slow fetches"**

* Your repository may be too large (>100 MB compressed)
* Use `.vhignore` to exclude unnecessary files
* Consider using Git submodules for large dependencies

**"Old code is running"**

* You need to fetch after pushing new commits
* Click **Fetch Repository** in project settings
* Consider setting up webhooks for automatic fetching

**"Can't see my private key field"**

* Make sure you're using the SSH URL format (`git@...`)
* The private key field only appears for SSH URLs

## Next Steps

**Configure your repository:**

* [Use .vhignore](/git-integration/use-vhignore.md) to exclude large files from workers
* [Manage Commits](/git-integration/manage-commits.md) to hide old branches

**Advanced workflows:**

* [Access Multiple Repositories](/git-integration/advanced-topics/submodules.md) with Git submodules
* [Clone Additional Repos](/git-integration/advanced-topics/clone-during-execution.md) during execution


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.valohai.com/git-integration/connect-repo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
