Skip to main content
Glama
bsreeram08

Git Repo Browser MCP

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

Implementation Reference

  • 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,
        };
      }
    }
  • 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";

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