Git Commits
Stage files, create commits, and push changes to remote repositories.
Stage Files
Add files to the staging area:
// Stage specific files
await sandbox.git.add({
repoPath: '/opt/app',
files: ['src/index.js', 'package.json']
});
// Stage all changes
await sandbox.git.add({
repoPath: '/opt/app',
files: ['.']
});await fetch(`${sandbox.url}/git/add`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
files: ['.']
})
});curl -X POST https://sandbox.oblien.com/git/add \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"message": "Files added to staging area",
"filesAdded": 2
}Create Commit
Commit staged changes:
await sandbox.git.commit({
repoPath: '/opt/app',
message: 'Add new feature',
author: {
name: 'AI Agent',
email: 'ai@oblien.com'
}
});await fetch(`${sandbox.url}/git/commit`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
message: 'Add new feature',
author: {
name: 'AI Agent',
email: 'ai@oblien.com'
}
})
});curl -X POST https://sandbox.oblien.com/git/commit \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"message": "Changes committed successfully",
"commit": "a1b2c3d4",
"branch": "main"
}Push to Remote
Push commits to remote repository:
await sandbox.git.push({
repoPath: '/opt/app',
branch: 'main',
auth: {
type: 'token',
token: process.env.GITHUB_TOKEN
}
});
// Force push (use with caution)
await sandbox.git.push({
repoPath: '/opt/app',
branch: 'feature-branch',
force: true,
auth: {
type: 'token',
token: process.env.GITHUB_TOKEN
}
});await fetch(`${sandbox.url}/git/push`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
branch: 'main',
auth: {
type: 'token',
token: process.env.GITHUB_TOKEN
}
})
});curl -X POST https://sandbox.oblien.com/git/push \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"message": "Changes pushed to remote",
"branch": "main",
"remote": "origin"
}Pull from Remote
Pull latest changes from remote:
await sandbox.git.pull({
repoPath: '/opt/app',
branch: 'main',
auth: {
type: 'token',
token: process.env.GITHUB_TOKEN
}
});await fetch(`${sandbox.url}/git/pull`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
branch: 'main',
auth: {
type: 'token',
token: process.env.GITHUB_TOKEN
}
})
});curl -X POST https://sandbox.oblien.com/git/pull \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"View Commit History
const history = await sandbox.git.history({
repoPath: '/opt/app',
limit: 10
});
history.commits.forEach(commit => {
console.log(`${commit.hash} - ${commit.message}`);
console.log(` Author: ${commit.author}`);
console.log(` Date: ${commit.date}`);
});const response = await fetch(`${sandbox.url}/git/history`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
limit: 10
})
});
const history = await response.json();curl -X POST https://sandbox.oblien.com/git/history \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"commits": [
{
"hash": "a1b2c3d4",
"message": "Add new feature",
"author": "AI Agent <ai@oblien.com>",
"date": "2025-10-26T12:00:00Z",
"branch": "main"
}
]
}Complete Workflow
// Make file changes
await sandbox.files.edit({
filePath: '/opt/app/src/api.js',
content: '// Updated API code'
});
await sandbox.files.create({
fullPath: '/opt/app/src/utils.js',
content: '// New utility functions'
});
// Check status
const status = await sandbox.git.status({
repoPath: '/opt/app'
});
console.log('Modified:', status.modified);
console.log('Untracked:', status.untracked);
// Stage changes
await sandbox.git.add({
repoPath: '/opt/app',
files: ['.']
});
// Commit
await sandbox.git.commit({
repoPath: '/opt/app',
message: 'Refactor API and add utilities',
author: {
name: 'AI Agent',
email: 'ai@oblien.com'
}
});
// Push to remote
await sandbox.git.push({
repoPath: '/opt/app',
branch: 'main',
auth: {
type: 'token',
token: process.env.GITHUB_TOKEN
}
});// (Make file changes)
// Check status
let response = await fetch(`${sandbox.url}/git/status`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ repoPath: '/opt/app' })
});
// Stage changes
await fetch(`${sandbox.url}/git/add`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
files: ['.']
})
});
// Commit
await fetch(`${sandbox.url}/git/commit`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
message: 'Refactor API and add utilities',
author: {
name: 'AI Agent',
email: 'ai@oblien.com'
}
})
});
// Push
await fetch(`${sandbox.url}/git/push`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
branch: 'main',
auth: {
type: 'token',
token: process.env.GITHUB_TOKEN
}
})
});curl -X POST https://sandbox.oblien.com/git/status \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Parameters
Add (Stage)
| Parameter | Type | Required | Description |
|---|---|---|---|
repoPath | string | Yes | Repository path |
files | string[] | Yes | Files to stage (use ['.'] for all) |
Commit
| Parameter | Type | Required | Description |
|---|---|---|---|
repoPath | string | Yes | Repository path |
message | string | Yes | Commit message |
author | object | No | Author info {name, email} |
Push
| Parameter | Type | Required | Description |
|---|---|---|---|
repoPath | string | Yes | Repository path |
branch | string | No | Branch to push |
force | boolean | No | Force push |
auth | object | No | Authentication config |
Pull
| Parameter | Type | Required | Description |
|---|---|---|---|
repoPath | string | Yes | Repository path |
branch | string | No | Branch to pull |
auth | object | No | Authentication config |
Best Practices
-
Write descriptive commit messages:
message: 'Add user authentication with JWT' // Not: 'Update files' -
Check status before committing: Review changes before staging
-
Stage specific files: Avoid staging unrelated changes
-
Configure author info: Always set name and email
-
Pull before push: Get latest changes to avoid conflicts
Next Steps
- Git Status - Check repository status
- Git Branches - Manage branches
- Git Clone - Clone repositories