Skip to main content
Glama

git_merge_branch

Merge a source branch into the current or target Git branch to integrate changes from development work into another branch.

Instructions

Merge a source branch into the current or target branch.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
source_branchYesBranch to merge from
target_branchNoBranch to merge into (optional, uses current branch if not provided)
no_fast_forwardNoWhether to create a merge commit even if fast-forward is possible

Implementation Reference

  • The handler function that executes the git merge operation using simpleGit, handling checkout if target branch specified, merge options, and error handling with conflict reporting.
    export async function handleGitMergeBranch({ repo_path, source_branch, target_branch = null, no_fast_forward = false, }) { try { const git = simpleGit(repo_path); // If target branch is specified, checkout to it first if (target_branch) { await git.checkout(target_branch); } // Perform the merge let mergeOptions = []; if (no_fast_forward) { mergeOptions = ["--no-ff"]; } const mergeResult = await git.merge([...mergeOptions, source_branch]); return { content: [ { type: "text", text: JSON.stringify( { success: true, result: mergeResult, message: `Merged ${source_branch} into ${ target_branch || "current branch" }`, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to merge branches: ${error.message}`, conflicts: error.git ? error.git.conflicts : null, }, null, 2 ), }, ], isError: true, }; } }
  • Defines the input schema, parameters, and description for the git_merge_branch tool used in tool listing and validation.
    { name: "git_merge_branch", description: "Merge a source branch into the current or target branch.", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, source_branch: { type: "string", description: "Branch to merge from", }, target_branch: { type: "string", description: "Branch to merge into (optional, uses current branch if not provided)", }, no_fast_forward: { type: "boolean", description: "Whether to create a merge commit even if fast-forward is possible", default: false, }, }, required: ["repo_path", "source_branch"], }, },
  • src/server.js:911-911 (registration)
    Maps the tool name 'git_merge_branch' to its handler function handleGitMergeBranch in the central handlersMap for request dispatching.
    git_merge_branch: handleGitMergeBranch,
  • Re-exports the handleGitMergeBranch function from branch-operations.js for convenient import in server.js.
    handleGitMergeBranch,
  • src/server.js:22-22 (registration)
    Imports the handleGitMergeBranch handler from handlers/index.js.
    handleGitMergeBranch,

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