Skip to main content
Glama

git_delete_branch

Remove a branch from a Git repository to clean up your project's branch structure. Specify the repository path and branch name to delete it.

Instructions

Delete a branch from the repository.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
branch_nameYesThe name of the branch to delete
forceNoWhether to force deletion

Implementation Reference

  • Core handler function that implements the git_delete_branch tool. Validates input, checks if branch is current, deletes using simpleGit, and returns structured MCP response.
    export async function handleGitDeleteBranch({ repo_path, branch_name, force = false, }) { try { const git = simpleGit(repo_path); // Get current branch to prevent deleting the active branch const currentBranch = await git.branch(); if (currentBranch.current === branch_name) { return { content: [ { type: "text", text: JSON.stringify( { error: "Cannot delete the currently checked out branch" }, null, 2 ), }, ], isError: true, }; } // Delete the branch if (force) { await git.deleteLocalBranch(branch_name, true); } else { await git.deleteLocalBranch(branch_name); } return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Deleted branch: ${branch_name}`, branch: branch_name, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to delete branch: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
  • Input schema definition and description for the git_delete_branch tool, included in the toolsList for MCP tool discovery.
    name: "git_delete_branch", description: "Delete a branch from the repository.", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, branch_name: { type: "string", description: "The name of the branch to delete", }, force: { type: "boolean", description: "Whether to force deletion", default: false, }, }, required: ["repo_path", "branch_name"], }, },
  • src/server.js:910-910 (registration)
    Registers the git_delete_branch tool name to its handler function in the server's handlersMap object for fast request dispatching.
    git_delete_branch: handleGitDeleteBranch,
  • Imports the handleGitDeleteBranch handler from branch-operations.js into the handlers index module.
    import { handleGitBranchDiff, handleGitCheckoutBranch, handleGitDeleteBranch, handleGitMergeBranch, } from "./branch-operations.js";
  • Re-exports handleGitDeleteBranch from the handlers index module for convenient import in server.js.
    handleGitBranchDiff, handleGitCheckoutBranch, handleGitDeleteBranch, 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