Skip to main content
Glama

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
NameRequiredDescriptionDefault
branchNoBranch to push (default: current branch)
forceNoWhether to force push
remoteNoRemote nameorigin
repo_pathYesThe path to the local Git repository

Implementation Reference

  • 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, }; } }
  • 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"],
  • Re-exports the handleGitPush function from remote-operations.js for use in server.js.
    import { handleGitPush, handleGitPull, handleGitRemote, } from "./remote-operations.js";

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bsreeram08/git-commands-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server