Git API 🟡 BETA

Git version control operations: status, diff, commit, push, and branch management


Base URL

/api/git

Authentication

All endpoints require a valid session token via Authorization: Bearer <token> header.


Endpoints

Get Status

GET /api/git/status

Returns the current git status of the repository including staged, modified, and untracked files.

Response:

{
  "success": true,
  "status": {
    "branch": "main",
    "ahead": 0,
    "behind": 2,
    "clean": false,
    "staged": [
      {
        "path": "botserver/src/main.rs",
        "status": "modified",
        "staging": "staged"
      }
    ],
    "modified": [
      {
        "path": "botserver/Cargo.toml",
        "status": "modified",
        "staging": "unstaged"
      }
    ],
    "untracked": [
      {
        "path": "botserver/src/new_module.rs",
        "status": "new"
      }
    ],
    "conflicts": []
  }
}

File Status Values:

StatusDescription
modifiedFile has been changed
newFile is untracked
deletedFile has been deleted
renamedFile has been renamed
copiedFile has been copied
conflictedMerge conflict present

Get Diff

GET /api/git/diff/:file

Returns the diff for a specific file (unstaged changes) or between commits.

ParameterTypeRequiredDescription
filestringYesFile path (path param)
stagedbooleanNoShow staged changes instead of unstaged (default: false)
fromstringNoCommit hash or ref for comparison (default: HEAD)
tostringNoTarget commit hash or ref (default: working tree)

Response:

{
  "success": true,
  "file": "botserver/src/main.rs",
  "diff": "--- a/botserver/src/main.rs\n+++ b/botserver/src/main.rs\n@@ -10,6 +10,8 @@\n use axum::Router;\n \n+use crate::api::routes;\n+\n #[tokio::main]\n async fn main() {\n-    let app = Router::new().route(\"/health\", get(health));\n+    let app = routes::create_router();\n }",
  "additions": 3,
  "deletions": 1,
  "binary": false
}

Commit Changes

POST /api/git/commit

Stages and commits changes to the repository.

ParameterTypeRequiredDescription
messagestringYesCommit message (JSON body)
filesarrayNoSpecific files to stage (JSON body). If omitted, stages all tracked modifications
allbooleanNoStage all modified and deleted files (default: false)
amendbooleanNoAmend the last commit (default: false)

Request Body:

{
  "message": "feat: Add new database admin endpoints\n\n- Added schema inspection endpoint\n- Added row CRUD operations\n- Added batch delete support",
  "files": ["botserver/src/api/database.rs"],
  "all": false
}

Response:

{
  "success": true,
  "commit": {
    "hash": "a1b2c3d4e5f6",
    "message": "feat: Add new database admin endpoints\n\n- Added schema inspection endpoint\n- Added row CRUD operations\n- Added batch delete support",
    "author": "Developer <dev@example.com>",
    "date": "2026-01-15T10:30:00Z",
    "files_changed": 1,
    "insertions": 85,
    "deletions": 12
  }
}

Push Changes

POST /api/git/push

Pushes committed changes to the remote repository.

ParameterTypeRequiredDescription
remotestringNoRemote name (default: origin)
branchstringNoBranch name (default: current branch)
forcebooleanNoForce push (default: false). Warning: use with caution

Request Body:

{
  "remote": "origin",
  "branch": "main",
  "force": false
}

Response:

{
  "success": true,
  "push": {
    "remote": "origin",
    "branch": "main",
    "commits_pushed": 1,
    "from": "a1b2c3d",
    "to": "d4e5f6a"
  }
}

List Branches

GET /api/git/branches

Lists all local and remote branches.

ParameterTypeRequiredDescription
remotebooleanNoInclude remote branches (default: true)

Response:

{
  "success": true,
  "current": "main",
  "branches": [
    {
      "name": "main",
      "current": true,
      "remote": false,
      "upstream": "origin/main",
      "ahead": 0,
      "behind": 0
    },
    {
      "name": "feature/new-api",
      "current": false,
      "remote": false,
      "upstream": "origin/feature/new-api",
      "ahead": 3,
      "behind": 1
    },
    {
      "name": "origin/feature/new-api",
      "current": false,
      "remote": true,
      "upstream": null,
      "ahead": 0,
      "behind": 0
    }
  ]
}

Create Branch

POST /api/git/branch/:name

Creates and optionally switches to a new branch.

ParameterTypeRequiredDescription
namestringYesNew branch name (path param)
fromstringNoStarting point — branch name or commit hash (default: current branch HEAD)
checkoutbooleanNoSwitch to the new branch after creation (default: true)

Request Body:

{
  "from": "main",
  "checkout": true
}

Response:

{
  "success": true,
  "branch": {
    "name": "feature/database-admin",
    "created_from": "main",
    "checkout": true
  },
  "message": "Branch 'feature/database-admin' created and checked out"
}

Get Log

GET /api/git/log

Returns recent commit history.

ParameterTypeRequiredDescription
countintegerNoNumber of commits to return (default: 20)
branchstringNoBranch to show log for (default: current branch)
sincestringNoOnly commits after this date (ISO 8601)
authorstringNoFilter by author name or email

Response:

{
  "success": true,
  "branch": "main",
  "commits": [
    {
      "hash": "a1b2c3d4e5f6",
      "short_hash": "a1b2c3d",
      "message": "feat: Add new database admin endpoints",
      "author": "Developer <dev@example.com>",
      "date": "2026-01-15T10:30:00Z",
      "files_changed": 3,
      "insertions": 120,
      "deletions": 15
    },
    {
      "hash": "b2c3d4e5f6a1",
      "short_hash": "b2c3d4e",
      "message": "fix: Correct WebSocket reconnection handling",
      "author": "Developer <dev@example.com>",
      "date": "2026-01-14T16:00:00Z",
      "files_changed": 1,
      "insertions": 8,
      "deletions": 3
    }
  ]
}

Error Responses

StatusDescription
400Invalid request (missing message, invalid branch name)
401Unauthorized (missing or invalid token)
403Forbidden (force push not allowed, or insufficient privileges)
404File or branch not found
409Conflict (branch already exists, merge in progress)
422Unprocessable Entity (nothing to commit, working tree clean)
500Internal server error (git operation failed)

Usage Example

// Check status
const status = await fetch('/api/git/status', {
  headers: { 'Authorization': 'Bearer mytoken' }
});
const { status: gitStatus } = await status.json();

// Get diff for a modified file
const diff = await fetch('/api/git/diff/botserver/src/main.rs', {
  headers: { 'Authorization': 'Bearer mytoken' }
});

// Create a branch and commit
await fetch('/api/git/branch/feature/my-change', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer mytoken',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ from: 'main', checkout: true })
});

await fetch('/api/git/commit', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer mytoken',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    message: 'feat: Add my new change',
    all: true
  })
});

// Push to remote
await fetch('/api/git/push', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer mytoken',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ remote: 'origin', branch: 'feature/my-change' })
});

See Also