branch_delete
Delete a specific branch in a Git repository by specifying the branch name and repository path. Enables precise branch management through the Git MCP Server for enhanced Git operations.
Instructions
Delete a branch
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Branch name | |
| path | No | Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo) |
Implementation Reference
- src/git-operations.ts:432-469 (handler)Primary implementation of the branch_delete tool handler. Validates repository and branch existence, ensures it's not the current branch, executes 'git branch -D <name>', handles errors, manages caching, and returns formatted success message.static async branchDelete({ path, name }: BranchOptions, context: GitToolContext): Promise<GitToolResult> { const resolvedPath = this.getPath({ path }); return await this.executeOperation( context.operation, resolvedPath, async () => { const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath); PathValidator.validateBranchName(name); await RepositoryValidator.validateBranchExists(repoPath, name, context.operation); const currentBranch = await RepositoryValidator.getCurrentBranch(repoPath, context.operation); if (currentBranch === name) { throw ErrorHandler.handleValidationError( new Error(`Cannot delete the currently checked out branch: ${name}`), { operation: context.operation, path: repoPath } ); } const result = await CommandExecutor.executeGitCommand( `branch -D ${name}`, context.operation, repoPath ); return { content: [{ type: 'text', text: `Branch '${name}' deleted successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'branch_delete', invalidateCache: true, // Invalidate branch cache stateType: RepoStateType.BRANCH } ); }
- src/tool-handler.ts:264-281 (registration)Registers the 'branch_delete' tool with the MCP server, defining its name, description, and input schema (path and name parameters).{ name: 'branch_delete', description: 'Delete a branch', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to repository. ${PATH_DESCRIPTION}`, }, name: { type: 'string', description: 'Branch name', }, }, required: ['name'], }, },
- src/tool-handler.ts:613-616 (handler)Dispatch handler in the tool executor switch statement that validates arguments using isBranchOptions and calls the main GitOperations.branchDelete handler.case 'branch_delete': { const validArgs = this.validateArguments(operation, args, isBranchOptions); return await GitOperations.branchDelete(validArgs, context); }
- Type definition for BranchDeleteOptions interface used in branch operations (though simplified in tool usage).export interface BranchDeleteOptions extends GitOperationOptions { /** Name of the branch to delete */ name: string; /** Whether to force delete even if not merged */ force?: boolean; /** Also delete the branch from remotes */ remote?: boolean; }