git_push
Push local Git repository changes to a remote repository. Use this tool to upload commits and synchronize code with remote servers.
Instructions
Push changes to a remote repository.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | The path to the local Git repository | |
| remote | No | Remote name | origin |
| branch | No | Branch to push (default: current branch) | |
| force | No | Whether to force push |
Implementation Reference
- src/handlers/remote-operations.js:11-65 (handler)The core handler function that executes the git push operation. It initializes simpleGit in the repo_path, auto-detects the current branch if none specified, pushes to the given remote/branch with optional --force, and returns an MCP-formatted response with success details or error.export async function handleGitPush({ repo_path, remote = "origin", branch = null, force = false, }) { try { const git = simpleGit(repo_path); // If no branch specified, get the current branch if (!branch) { const branchInfo = await git.branch(); branch = branchInfo.current; } // Perform the push let pushOptions = []; if (force) { pushOptions.push("--force"); } const pushResult = await git.push(remote, branch, pushOptions); return { content: [ { type: "text", text: JSON.stringify( { success: true, result: pushResult, message: `Pushed ${branch} to ${remote}`, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to push changes: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
- src/server.js:419-446 (schema)Defines the input schema and metadata for the 'git_push' tool in the toolsList array, used by ListToolsRequestHandler. Specifies required repo_path and optional remote, branch, force parameters.{ name: "git_push", description: "Push changes to a remote repository.", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, remote: { type: "string", description: "Remote name", default: "origin", }, branch: { type: "string", description: "Branch to push (default: current branch)", }, force: { type: "boolean", description: "Whether to force push", default: false, }, }, required: ["repo_path"], }, },
- src/server.js:912-912 (registration)Registers 'git_push' tool name to the handleGitPush function in the handlersMap object, enabling fast lookup during CallToolRequest handling.git_push: handleGitPush,
- src/server.js:21-24 (registration)Imports the handleGitPush handler from handlers/index.js (which re-exports from remote-operations.js) into the server class.handleGitDeleteBranch, handleGitMergeBranch, handleGitPush, handleGitPull,
- Imports simpleGit utility from common.js, used throughout the handler for Git operations.import { simpleGit } from "./common.js";