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

# Clone a private repository into a training job

> Pull code from a private GitHub repository into a training container, with SSH agent forwarding for interactive work or a personal access token for unattended jobs.

Training jobs sometimes need code from a private GitHub repo: an internal library, a dataset loader, or the training script itself. The right flow depends on whether you're connecting interactively or running unattended.

## Prerequisites

* A private GitHub repository, and permission to read it.
* For the agent forwarding flow, SSH set up on your machine and a running job with SSH enabled. See [Set up SSH](https://docs.baseten.co/training/ssh-setup.md) and [Connect over SSH](https://docs.baseten.co/training/ssh.md).
* For the token flow, a GitHub personal access token with read access to the repository, and the Baseten CLI to store it as a secret.

## With SSH agent forwarding

Agent forwarding works only over SSH. For a [remote tunnel session](https://docs.baseten.co/training/interactive-sessions.md), use the [personal access token flow](#with-a-personal-access-token).

**To clone a private repository with agent forwarding**:

1. Load your GitHub-registered key into the local agent:

   ```bash theme={"system"}
   ssh-add ~/.ssh/id_ed25519
   ```

2. Connect to the job with agent forwarding, then confirm the container can reach GitHub:

   ```bash theme={"system"}
   ssh -A training-job-<job_id>-0.ssh.baseten.co
   ssh -T git@github.com
   ```

   GitHub's reply names your account and confirms `You've successfully authenticated`.

3. Clone the repository over SSH from inside the container:

   ```bash theme={"system"}
   git clone git@github.com:<org>/<repo>.git
   ```

   The command reports `Cloning into '<repo>'...` and returns to your prompt when the clone finishes.

The `~/.ssh/config` block written by [`baseten ssh setup`](https://docs.baseten.co/reference/cli/baseten/ssh) doesn't include `ForwardAgent yes`. Pass `-A` on every connection, or append `ForwardAgent yes` to the `Match host training-job-*.ssh.baseten.co` block in `~/.ssh/config`.

The SSH agent forgets added keys on reboot. On macOS, add keys to your login keychain to reload them automatically:

```bash theme={"system"}
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
```

Or set `AddKeysToAgent yes` and `UseKeychain yes` in `~/.ssh/config`. On Windows, the OpenSSH `ssh-agent` service keeps added keys across reboots.

## With a personal access token

Pull the repository before you connect, for example from [`start_commands`](https://docs.baseten.co/reference/sdk/training#param-start-commands).

> [!WARNING]
>
> Don't pass the token as a plain string in [`environment_variables`](https://docs.baseten.co/reference/sdk/training#runtime). Use [`SecretReference`](https://docs.baseten.co/reference/sdk/training#secretreference) so the value stays in the secret store and out of source control.

**To clone a private repository with a personal access token**:

1. Store a [fine-grained GitHub personal access token](https://github.com/settings/personal-access-tokens) with **Contents: Read-only** as a [Baseten secret](https://docs.baseten.co/organization/secrets.md) named `github_pat`.

2. Inject the secret in `config.py`:

   ```python config.py theme={"system"}
   from truss_train.definitions import Runtime, SecretReference

   runtime = Runtime(
       start_commands=[
           "git clone https://x-access-token:${GITHUB_PAT}@github.com/<org>/<repo>.git $BT_WORKING_DIR/repo",
       ],
       environment_variables={"GITHUB_PAT": SecretReference(name="github_pat")},
   )
   ```

   The `x-access-token` username is GitHub's convention for token-based HTTPS auth. `$GITHUB_PAT` stays set for the container's lifetime, so later `git pull` or `git fetch` commands reuse the same credential.

3. Pass `runtime` to the [`runtime`](https://docs.baseten.co/reference/sdk/training#runtime) argument of the job in the same file.

4. Push the job:

   ```bash theme={"system"}
   baseten train push --config config.py
   ```

5. Read the job's logs to confirm the clone landed:

   ```bash theme={"system"}
   baseten train job logs --job-id <job_id> --tail
   ```

   The `git clone` in `start_commands` prints `Cloning into '<repo>'...`, and any later command that reads `$BT_WORKING_DIR/repo` prints its own output.

## Next steps

* [Connect to a training job over SSH](https://docs.baseten.co/training/ssh.md): Open a shell in the container.
* [Manage sessions](https://docs.baseten.co/training/manage-sessions.md): Check session status and change the trigger.
