Skip to main content
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 and Connect over SSH.
  • 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, use the personal access token flow. To clone a private repository with agent forwarding:
  1. Load your GitHub-registered key into the local agent:
  2. Connect to the job with agent forwarding, then confirm the container can reach GitHub:
    GitHub’s reply names your account and confirms You've successfully authenticated.
  3. Clone the repository over SSH from inside the container:
    The command reports Cloning into '<repo>'... and returns to your prompt when the clone finishes.
The ~/.ssh/config block written by baseten ssh setup 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:
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.
Don’t pass the token as a plain string in environment_variables. Use 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 with Contents: Read-only as a Baseten secret named github_pat.
  2. Inject the secret in config.py:
    config.py
    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 argument of the job in the same file.
  4. Push the job:
  5. Read the job’s logs to confirm the clone landed:
    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