Git Status
Check the current state of your Git repository, view modified files, and track changes.
Get Repository Status
const status = await sandbox.git.status({
repoPath: '/opt/app'
});
console.log('Current branch:', status.branch);
console.log('Modified files:', status.modified);
console.log('Untracked files:', status.untracked);
console.log('Staged files:', status.staged);const response = await fetch(`${sandbox.url}/git/status`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app'
})
});
const status = await response.json();curl -X POST https://sandbox.oblien.com/git/status \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"branch": "main",
"modified": [
"src/index.js",
"package.json"
],
"untracked": [
"src/new-file.js"
],
"staged": [
"README.md"
],
"deleted": [],
"ahead": 2,
"behind": 0,
"clean": false
}Status Fields
| Field | Type | Description |
|---|---|---|
branch | string | Current branch name |
modified | string[] | Modified files not staged |
untracked | string[] | New files not tracked |
staged | string[] | Files staged for commit |
deleted | string[] | Deleted files |
ahead | number | Commits ahead of remote |
behind | number | Commits behind remote |
clean | boolean | True if no changes |
Complete Example
// Check status
const status = await sandbox.git.status({
repoPath: '/opt/app'
});
if (status.clean) {
console.log('Working directory clean');
} else {
console.log(`${status.modified.length} modified files`);
console.log(`${status.untracked.length} untracked files`);
console.log(`${status.staged.length} staged files`);
// List modified files
if (status.modified.length > 0) {
console.log('\nModified files:');
status.modified.forEach(file => console.log(` - ${file}`));
}
// List untracked files
if (status.untracked.length > 0) {
console.log('\nUntracked files:');
status.untracked.forEach(file => console.log(` - ${file}`));
}
}
// Check sync status
if (status.ahead > 0) {
console.log(`\nYou are ${status.ahead} commits ahead of remote`);
}
if (status.behind > 0) {
console.log(`\nYou are ${status.behind} commits behind remote`);
}const response = await fetch(`${sandbox.url}/git/status`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app'
})
});
const status = await response.json();
if (status.clean) {
console.log('Working directory clean');
} else {
console.log(`${status.modified.length} modified files`);
console.log(`${status.untracked.length} untracked files`);
}curl -X POST https://sandbox.oblien.com/git/status \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Conditional Workflows
Use status to make decisions:
const status = await sandbox.git.status({ repoPath: '/opt/app' });
// Only commit if there are changes
if (!status.clean) {
await sandbox.git.add({ repoPath: '/opt/app', files: ['.'] });
await sandbox.git.commit({
repoPath: '/opt/app',
message: 'Auto-commit changes'
});
}
// Only pull if behind
if (status.behind > 0) {
await sandbox.git.pull({
repoPath: '/opt/app',
auth: { type: 'token', token: process.env.GITHUB_TOKEN }
});
}
// Only push if ahead
if (status.ahead > 0) {
await sandbox.git.push({
repoPath: '/opt/app',
auth: { type: 'token', token: process.env.GITHUB_TOKEN }
});
}Check If Git Repository
Verify a directory is a Git repository:
const result = await sandbox.git.check({
repoPath: '/opt/app'
});
if (result.isGitRepository) {
console.log('This is a Git repository');
const status = await sandbox.git.status({ repoPath: '/opt/app' });
} else {
console.log('Not a Git repository');
// Initialize if needed
await sandbox.git.init({ repoPath: '/opt/app' });
}const response = await fetch(`${sandbox.url}/git/check`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app'
})
});
const result = await response.json();curl -X POST https://sandbox.oblien.com/git/check \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
repoPath | string | Yes | Repository path |
Best Practices
-
Check status before operations: Always verify repository state before committing
-
Handle clean state: Check if there are changes before staging
-
Monitor sync status: Check
aheadandbehindto stay synced with remote -
List untracked files: Review new files before staging
Next Steps
- Git Commits - Stage and commit changes
- Git Branches - Manage branches
- Git Clone - Clone repositories