Skip to main content
Glama

git_branch_diff

Compare changes between two branches in a Git repository to identify file differences, with an option to include detailed diff patches for precise analysis.

Instructions

Compare two branches and show files changed between them.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_urlYesThe URL of the Git repository
show_patchNoWhether to include the actual diff patches
source_branchYesThe source branch name
target_branchYesThe target branch name

Implementation Reference

  • Core handler function that executes the git_branch_diff tool: clones repo, fetches branches if needed, computes diff summary or patch, gets commit count, and formats response.
    export async function handleGitBranchDiff({ repo_url, source_branch, target_branch, show_patch = false, }) { try { const repoPath = await cloneRepo(repo_url); const git = simpleGit(repoPath); // Make sure both branches exist locally const branches = await git.branch(); if (!branches.all.includes(source_branch)) { await git.fetch("origin", source_branch); await git.checkout(source_branch); } if (!branches.all.includes(target_branch)) { await git.fetch("origin", target_branch); } // Get the diff between branches const diffOptions = ["--name-status"]; if (show_patch) { diffOptions.push("--patch"); } const diff = await git.diff([ ...diffOptions, `${target_branch}...${source_branch}`, ]); // Get commit range information const logSummary = await git.log({ from: target_branch, to: source_branch, }); const result = { commits_count: logSummary.total, diff_summary: diff, }; return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to get branch diff: ${error.message}` }, null, 2 ), }, ], isError: true, }; }
  • Input schema definition for git_branch_diff tool registration, specifying parameters and validation rules.
    name: "git_branch_diff", description: "Compare two branches and show files changed between them.", inputSchema: { type: "object", properties: { repo_url: { type: "string", description: "The URL of the Git repository", }, source_branch: { type: "string", description: "The source branch name", }, target_branch: { type: "string", description: "The target branch name", }, show_patch: { type: "boolean", description: "Whether to include the actual diff patches", default: false, }, }, required: ["repo_url", "source_branch", "target_branch"], },
  • src/server.js:902-902 (registration)
    Maps the tool name 'git_branch_diff' to its handler function in the central handlersMap used by the MCP server.
    git_branch_diff: handleGitBranchDiff,
  • src/server.js:13-13 (registration)
    Imports the handleGitBranchDiff handler from handlers/index.js for use in server.js registrations.
    handleGitBranchDiff,
  • Re-exports handleGitBranchDiff from branch-operations.js to centralize imports in server.js.
    handleGitBranchDiff,

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