git_push
Push changes from a local Git repository to a specified remote branch. Configure repo path, remote, branch, and force options to streamline updates.
Instructions
Push changes to a remote repository.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | No | Branch to push (default: current branch) | |
| force | No | Whether to force push | |
| remote | No | Remote name | origin |
| repo_path | Yes | The path to the local Git repository |
Implementation Reference
- src/handlers/remote-operations.js:11-65 (handler)Core implementation of the git_push tool handler. Uses simpleGit to push the specified branch to the remote, handling defaults for branch and options like force push. Returns structured MCP response with success/error content.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)Tool schema definition for git_push, specifying name, description, input parameters with types, descriptions, defaults, and required fields.{ 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:898-927 (registration)Registers the git_push handler in the server's handlersMap object, mapping the tool name to the handleGitPush function for execution.this.handlersMap = { // Primary handlers git_directory_structure: handleGitDirectoryStructure, git_read_files: handleGitReadFiles, git_branch_diff: handleGitBranchDiff, git_commit_history: handleGitCommitHistory, git_commits_details: handleGitCommitsDetails, git_local_changes: handleGitLocalChanges, git_search_code: handleGitSearchCode, git_commit: handleGitCommit, git_track: handleGitTrack, git_checkout_branch: handleGitCheckoutBranch, git_delete_branch: handleGitDeleteBranch, git_merge_branch: handleGitMergeBranch, git_push: handleGitPush, git_pull: handleGitPull, git_stash: handleGitStash, git_create_tag: handleGitCreateTag, git_rebase: handleGitRebase, git_config: handleGitConfig, git_reset: handleGitReset, git_archive: handleGitArchive, git_attributes: handleGitAttributes, git_blame: handleGitBlame, git_clean: handleGitClean, git_hooks: handleGitHooks, git_lfs: handleGitLFS, git_lfs_fetch: handleGitLFSFetch, git_revert: handleGitRevert, };
- src/server.js:874-875 (registration)Categorizes git_push under 'remote' operations for organizational purposes.remote: ["git_push", "git_pull"], stash: ["git_stash"],
- src/handlers/index.js:20-24 (helper)Re-exports the handleGitPush function from remote-operations.js for use in server.js.import { handleGitPush, handleGitPull, handleGitRemote, } from "./remote-operations.js";