Git Branches
Create, list, and switch between Git branches in your sandbox.
Get Current Branch
const result = await sandbox.git.getCurrentBranch({
repoPath: '/opt/app'
});
console.log(`Current branch: ${result.branch}`);const response = await fetch(`${sandbox.url}/git/branch/current`, {
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/branch/current \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"branch": "main"
}List Branches
// List local branches only
const result = await sandbox.git.listBranches({
repoPath: '/opt/app'
});
console.log('Local branches:', result.branches);
// List all branches including remote
const allBranches = await sandbox.git.listBranches({
repoPath: '/opt/app',
includeRemote: true
});
console.log('All branches:', allBranches.branches);const response = await fetch(`${sandbox.url}/git/branch/list`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
includeRemote: true
})
});
const result = await response.json();curl -X POST https://sandbox.oblien.com/git/branch/list \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"branches": [
"main",
"develop",
"feature/new-api",
"origin/main",
"origin/develop"
],
"current": "main"
}Create Branch
// Create branch without checkout
await sandbox.git.createBranch({
repoPath: '/opt/app',
branchName: 'feature/new-feature'
});
// Create and checkout
await sandbox.git.createBranch({
repoPath: '/opt/app',
branchName: 'feature/new-feature',
checkout: true
});await fetch(`${sandbox.url}/git/branch/create`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
branchName: 'feature/new-feature',
checkout: true
})
});curl -X POST https://sandbox.oblien.com/git/branch/create \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"message": "Branch created successfully",
"branch": "feature/new-feature"
}Checkout Branch
Switch to an existing branch:
await sandbox.git.checkoutBranch({
repoPath: '/opt/app',
branchName: 'develop'
});await fetch(`${sandbox.url}/git/branch/checkout`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
branchName: 'develop'
})
});curl -X POST https://sandbox.oblien.com/git/branch/checkout \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Response:
{
"success": true,
"message": "Switched to branch 'develop'",
"branch": "develop"
}Complete Branch Workflow
// Check current branch
const current = await sandbox.git.getCurrentBranch({
repoPath: '/opt/app'
});
console.log('Current:', current.branch);
// List all branches
const branches = await sandbox.git.listBranches({
repoPath: '/opt/app'
});
console.log('Branches:', branches.branches);
// Create new feature branch
await sandbox.git.createBranch({
repoPath: '/opt/app',
branchName: 'feature/authentication',
checkout: true
});
// Make changes and commit
await sandbox.files.edit({
filePath: '/opt/app/auth.js',
content: '// Authentication code'
});
await sandbox.git.add({
repoPath: '/opt/app',
files: ['auth.js']
});
await sandbox.git.commit({
repoPath: '/opt/app',
message: 'Add authentication'
});
// Switch back to main
await sandbox.git.checkoutBranch({
repoPath: '/opt/app',
branchName: 'main'
});// Check current branch
let response = await fetch(`${sandbox.url}/git/branch/current`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ repoPath: '/opt/app' })
});
// Create new feature branch
await fetch(`${sandbox.url}/git/branch/create`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
branchName: 'feature/authentication',
checkout: true
})
});
// (Make changes, commit)
// Switch back to main
await fetch(`${sandbox.url}/git/branch/checkout`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${sandbox.token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
repoPath: '/opt/app',
branchName: 'main'
})
});curl -X POST https://sandbox.oblien.com/git/branch/current \
-H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
-H "Content-Type: application/json"Parameters
List Branches
| Parameter | Type | Required | Description |
|---|---|---|---|
repoPath | string | Yes | Repository path |
includeRemote | boolean | No | Include remote branches |
Create Branch
| Parameter | Type | Required | Description |
|---|---|---|---|
repoPath | string | Yes | Repository path |
branchName | string | Yes | New branch name |
checkout | boolean | No | Checkout after creation |
Checkout Branch
| Parameter | Type | Required | Description |
|---|---|---|---|
repoPath | string | Yes | Repository path |
branchName | string | Yes | Branch to checkout |
Best Practices
-
Use descriptive branch names:
'feature/user-authentication' 'bugfix/login-error' 'hotfix/security-patch' -
Check current branch before operations: Always verify you're on the correct branch
-
Create branches for features: Never commit directly to main/master
-
List branches to verify: Check branch exists before checkout
Next Steps
- Git Commits - Commit and push changes
- Git Status - Check repository status
- Git Clone - Clone repositories