POST /v1/agents/runtime/{runtime_id}/git/branch/delete
import uuid
from gravixlayer import GravixLayer
client = GravixLayer() # defaults to cloud="aws", region="us-east-1"
policy = client.network_policies.create(
name=f"git-github-{uuid.uuid4().hex[:8]}",
egress_mode="allowlist",
rules=[{"destination": "github.com", "port": 443, "protocol": "tcp"}],
)
sandbox = client.runtime.create(network_policy_ids=[policy.id]) # defaults to template="base-small"
sandbox.git.clone(
url="https://github.com/octocat/Hello-World.git",
path="/workspace/repo",
)
sandbox.git.create_branch("/workspace/repo", "tmp-branch")
sandbox.git.checkout("/workspace/repo", "master")
r = sandbox.git.delete_branch("/workspace/repo", "tmp-branch")
print(r.success, r.exit_code)
# Force delete: sandbox.git.delete_branch("/workspace/repo", "name", force=True)
sandbox.kill()
client.network_policies.delete(policy.id)
import { GravixLayer } from 'gravixlayer';
const client = new GravixLayer(); // defaults to cloud="aws", region="us-east-1"
const policy = await client.networkPolicies.create(`git-github-${Date.now()}`, {
egressMode: 'allowlist',
rules: [{ destination: 'github.com', port: 443, protocol: 'tcp' }],
});
const sandbox = await client.runtime.create({ networkPolicyIds: [policy.id] }); // defaults to template="base-small"
await sandbox.git.clone('https://github.com/octocat/Hello-World.git', '/workspace/repo');
await sandbox.git.createBranch("/workspace/repo", "tmp-branch");
await sandbox.git.checkout("/workspace/repo", "master");
const r = await sandbox.git.deleteBranch("/workspace/repo", "tmp-branch");
console.log(r.success, r.exitCode);
// Force delete: await sandbox.git.deleteBranch('/workspace/repo', 'name', true)
await sandbox.kill();
await client.networkPolicies.delete(policy.id);
gravixlayer runtime git branch-delete "$RT" tmp-branch --path /workspace/repo
# Force delete an unmerged branch
gravixlayer runtime git branch-delete "$RT" tmp-branch \
--path /workspace/repo \
--force
curl -X POST "https://api.gravixlayer.ai/v1/agents/runtime/$RT/git/branch/delete" \
-H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"repository_path": "/workspace/repo",
"branch_name": "tmp-branch",
"force": false
}'
force, git refuses to delete a branch whose commits are not merged
elsewhere; force maps to git branch -D and discards them.
This deletes the local branch only. To delete the remote branch, push a refspec
with an empty source, for example :refs/heads/tmp-branch.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
repository_path | string | Yes | Path to the repository root inside the runtime |
branch_name | string | Yes | Branch to delete |
force | boolean | No | If true, use force delete (-D); otherwise safe delete (-d) |
Response
| Field | Type | Description |
|---|---|---|
success | boolean | Whether the git command completed successfully |
exit_code | integer | Process exit code from git |
stdout | string | Standard output from git |
stderr | string | Standard error from git |
error | string | Error message when the operation fails |