Git Clone & Repository Setup
Learn how to clone repositories and initialize Git in your Sandbox environment.
Clone Repository
Clone any Git repository into your sandbox.
// Using SDK
const result = await sandbox.git.clone({
url: 'https://github.com/user/repository',
targetDir: '/opt/app',
branch: 'main',
auth: {
type: 'token',
token: 'ghp_your_github_token'
}
});
POST /git/clone HTTP/1.1
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
{
"url": "https://github.com/user/repository",
"targetDir": "/opt/app",
"branch": "main",
"auth": {
"type": "token",
"token": "ghp_your_github_token"
}
}
Response:
{
"success": true,
"message": "Repository cloned successfully",
"path": "/opt/app",
"branch": "main",
"commit": "a1b2c3d4e5f6"
}
Parameters:
Parameter | Type | Required | Description |
---|---|---|---|
url | string | Yes | Git repository URL |
targetDir | string | Yes | Directory to clone into |
branch | string | No | Branch to clone (default: default branch) |
auth | object | No | Authentication configuration |
root | boolean | No | Clone as root directory (default: true) |
Authentication Methods
1. GitHub Personal Access Token
await sandbox.git.clone({
url: 'https://github.com/user/private-repo',
targetDir: '/opt/app',
auth: {
type: 'token',
token: 'ghp_xxxxxxxxxxxxxxxxxxxx'
}
});
POST /git/clone HTTP/1.1
Content-Type: application/json
{
"url": "https://github.com/user/private-repo",
"targetDir": "/opt/app",
"auth": {
"type": "token",
"token": "ghp_xxxxxxxxxxxxxxxxxxxx"
}
}
2. SSH Key
await sandbox.git.clone({
url: 'git@github.com:user/repo.git',
targetDir: '/opt/app',
auth: {
type: 'ssh',
keyName: 'id_rsa' // SSH key stored in sandbox
}
});
POST /git/clone HTTP/1.1
Content-Type: application/json
{
"url": "git@github.com:user/repo.git",
"targetDir": "/opt/app",
"auth": {
"type": "ssh",
"keyName": "id_rsa"
}
}
3. Username & Password (HTTPS)
await sandbox.git.clone({
url: 'https://gitlab.com/user/repo',
targetDir: '/opt/app',
auth: {
type: 'basic',
username: 'your-username',
password: 'your-password'
}
});
Clone Options
Clone Specific Branch
// Clone a specific branch
await sandbox.git.clone({
url: 'https://github.com/user/repo',
targetDir: '/opt/app',
branch: 'develop'
});
Clone to Custom Directory
// Clone into a subdirectory
await sandbox.git.clone({
url: 'https://github.com/user/repo',
targetDir: '/opt/app/projects/myproject',
root: false // Not the root app directory
});
Initialize New Repository
Create a new Git repository from scratch.
// Using SDK
await sandbox.git.init({
repoPath: '/opt/app'
});
POST /git/init HTTP/1.1
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
{
"repoPath": "/opt/app"
}
Response:
{
"success": true,
"message": "Repository initialized",
"path": "/opt/app"
}
Configure Git User
Set Git user name and email for commits.
// Using SDK
await sandbox.git.config.user({
repoPath: '/opt/app',
name: 'AI Agent',
email: 'ai@oblien.com'
});
POST /git/config/user HTTP/1.1
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
{
"repoPath": "/opt/app",
"name": "AI Agent",
"email": "ai@oblien.com"
}
Response:
{
"success": true,
"message": "Git user configured",
"name": "AI Agent",
"email": "ai@oblien.com"
}
Check if Git Repository
Verify if a directory is a Git repository.
// Using SDK
const isGit = await sandbox.git.check({
repoPath: '/opt/app'
});
if (isGit.isGitRepository) {
console.log('This is a Git repository');
}
POST /git/check HTTP/1.1
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
{
"repoPath": "/opt/app"
}
Response:
{
"success": true,
"isGitRepository": true
}
List Available SSH Keys
Get list of SSH keys available in the sandbox.
// Using SDK
const keys = await sandbox.git.keys();
GET /git/keys HTTP/1.1
Authorization: Bearer YOUR_TOKEN
Response:
{
"success": true,
"keys": [
{
"name": "id_rsa",
"fingerprint": "SHA256:abc123...",
"type": "RSA",
"bits": 4096
}
]
}
Common Workflows
Clone Private Repository
// 1. Clone with token
const result = await sandbox.git.clone({
url: 'https://github.com/company/private-repo',
targetDir: '/opt/app',
auth: {
type: 'token',
token: process.env.GITHUB_TOKEN
}
});
// 2. Configure user for commits
await sandbox.git.config.user({
repoPath: '/opt/app',
name: 'Bot',
email: 'bot@company.com'
});
// 3. Verify setup
const status = await sandbox.git.status({ repoPath: '/opt/app' });
console.log('Repository ready:', status);
Clone Multiple Repositories
const repos = [
{ url: 'https://github.com/user/repo1', dir: '/opt/app/repo1' },
{ url: 'https://github.com/user/repo2', dir: '/opt/app/repo2' },
];
for (const repo of repos) {
await sandbox.git.clone({
url: repo.url,
targetDir: repo.dir,
root: false
});
}
Error Handling
try {
await sandbox.git.clone({
url: 'https://github.com/user/repo',
targetDir: '/opt/app'
});
} catch (error) {
if (error.message.includes('Authentication failed')) {
console.log('Invalid credentials');
} else if (error.message.includes('Repository not found')) {
console.log('Repository does not exist');
} else if (error.message.includes('already exists')) {
console.log('Directory is not empty');
}
}
Next Steps
- Learn about Git Branches
- Explore Git Commits
- Check Git Status