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
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | The path to the local Git repository | |
| source_branch | Yes | Branch to merge from | |
| target_branch | No | Branch to merge into (optional, uses current branch if not provided) | |
| no_fast_forward | No | Whether 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, }; } }
- src/server.js:210-238 (schema)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,
- src/handlers/index.js:58-58 (registration)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,