Skip to main content
Glama

git-branches

Manage Git branch lifecycle with create, list, delete, merge, and compare operations. Includes safety warnings for destructive actions like branch deletion to protect commit history.

Instructions

Git branch management tool for branch lifecycle operations. Supports create, list, get, delete, merge, and compare operations. Includes safety warnings for destructive operations like branch deletion.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesThe branch operation to perform. WARNING: delete operation permanently removes branches and their commit history.
baseBranchNoBase branch for comparison (required for compare action)
branchNameNoName of the branch (required for create, get, delete, merge)
checkoutNoCheckout branch after creation (for create action)
compareBranchNoBranch to compare against base (required for compare action)
forceNoForce operation (for delete, merge actions)
ownerNoRepository owner (for remote operations)
projectPathYesAbsolute path to the project directory
providerNoProvider for remote operations (if supported)
remoteNoRemote name (default: origin)
repoNoRepository name (for remote operations)
sourceBranchNoSource branch to create from (for create action)
targetBranchNoTarget branch to merge into (for merge action)

Implementation Reference

  • Main execute method of GitBranchesTool that validates parameters and routes to local or remote branch operations (create, list, get, delete, merge, compare). All logic is implemented in this class's private methods.
    /**
     * Execute git-branches operation
     */
    async execute(params: GitBranchesParams): Promise<ToolResult> {
      const startTime = Date.now();
    
      try {
        // Validate basic parameters
        const validation = ParameterValidator.validateToolParams('git-branches', params);
        if (!validation.isValid) {
          return OperationErrorHandler.createToolError(
            'VALIDATION_ERROR',
            `Parameter validation failed: ${validation.errors.join(', ')}`,
            params.action,
            { validationErrors: validation.errors },
            validation.suggestions
          );
        }
    
        // Validate operation-specific parameters
        const operationValidation = ParameterValidator.validateOperationParams('git-branches', params.action, params);
        if (!operationValidation.isValid) {
          return OperationErrorHandler.createToolError(
            'VALIDATION_ERROR',
            `Operation validation failed: ${operationValidation.errors.join(', ')}`,
            params.action,
            { validationErrors: operationValidation.errors },
            operationValidation.suggestions
          );
        }
    
        // Route to appropriate handler
        const isRemoteOperation = this.isRemoteOperation(params.action);
        
        if (isRemoteOperation) {
          return await this.executeRemoteOperation(params, startTime);
        } else {
          return await this.executeLocalOperation(params, startTime);
        }
    
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : 'Unknown error';
        return OperationErrorHandler.createToolError(
          'EXECUTION_ERROR',
          `Failed to execute ${params.action}: ${errorMessage}`,
          params.action,
          { error: errorMessage },
          ['Check the error details and try again']
        );
      }
    }
  • Tool schema definition including input schema, error codes, warnings, and usage examples for MCP registration.
    static getToolSchema() {
      return {
        name: 'git-branches',
        description: 'Git branch management tool for branch lifecycle operations. Supports create, list, get, delete, merge, and compare operations. Includes safety warnings for destructive operations like branch deletion. In universal mode (GIT_MCP_MODE=universal), automatically executes on both GitHub and Gitea providers.',
        inputSchema: {
          type: 'object',
          properties: {
            action: {
              type: 'string',
              enum: ['create', 'list', 'get', 'delete', 'merge', 'compare'],
              description: 'The branch operation to perform. WARNING: delete operation permanently removes branches and their commit history.'
            },
            projectPath: {
              type: 'string',
              description: 'Absolute path to the project directory'
            },
            provider: {
              type: 'string',
              enum: ['github', 'gitea', 'both'],
              description: 'Provider for remote operations (if supported)'
            },
            branchName: {
              type: 'string',
              description: 'Name of the branch (required for create, get, delete, merge)'
            },
            sourceBranch: {
              type: 'string',
              description: 'Source branch to create from (for create action)'
            },
            targetBranch: {
              type: 'string',
              description: 'Target branch to merge into (for merge action)'
            },
            baseBranch: {
              type: 'string',
              description: 'Base branch for comparison (required for compare action)'
            },
            compareBranch: {
              type: 'string',
              description: 'Branch to compare against base (required for compare action)'
            },
            force: {
              type: 'boolean',
              description: 'Force operation (for delete, merge actions)'
            },
            remote: {
              type: 'string',
              description: 'Remote name (default: origin)'
            },
            checkout: {
              type: 'boolean',
              description: 'Checkout branch after creation (for create action)'
            },
            repo: {
              type: 'string',
              description: 'Repository name (for remote operations)'
            }
          },
          required: ['action', 'projectPath'],
          additionalProperties: false
        },
        errorCodes: {
          'VALIDATION_ERROR': 'Parameter validation failed - check required parameters and format',
          'BRANCH_EXISTS': 'Branch already exists - use different name or delete existing branch',
          'BRANCH_NOT_FOUND': 'Branch not found - check branch name and remote configuration',
          'MERGE_CONFLICT': 'Merge conflicts detected - resolve conflicts before completing merge',
          'DIRTY_WORKING_TREE': 'Working directory has uncommitted changes - commit or stash first',
          'NOT_A_GIT_REPOSITORY': 'Directory is not a Git repository - use git init first',
          'PERMISSION_DENIED': 'Permission denied - check access rights and credentials'
        },
        warnings: {
          'delete': 'Branch deletion is permanent and cannot be undone. Ensure branch is merged or no longer needed.',
          'force': 'Force operations can cause data loss. Use with extreme caution.'
        },
        examples: [
          {
            description: 'List all branches',
            input: {
              action: 'list',
              projectPath: '/path/to/project'
            }
          },
          {
            description: 'Create new feature branch',
            input: {
              action: 'create',
              projectPath: '/path/to/project',
              branchName: 'feature/new-feature',
              sourceBranch: 'main',
              checkout: true
            }
          },
          {
            description: 'Compare two branches',
            input: {
              action: 'compare',
              projectPath: '/path/to/project',
              baseBranch: 'main',
              compareBranch: 'feature/new-feature'
            }
          }
        ]
      };
    }
  • src/server.ts:88-89 (registration)
    Instantiation of GitBranchesTool instance during server initialization.
    this.gitBranchesTool = new GitBranchesTool(providerConfig);
    this.gitFilesTool = new GitFilesTool(providerConfig);
  • src/server.ts:474-475 (registration)
    Tool execution dispatch in the MCP CallToolRequest handler switch statement.
    case 'git-branches':
      return await this.gitBranchesTool.execute(args);
  • src/server.ts:125-127 (registration)
    Tool schema registration in the MCP ListToolsRequest handler.
    GitWorkflowTool.getToolSchema(),
    GitFilesTool.getToolSchema(),
    GitBranchesTool.getToolSchema(),
  • Parameter validation configuration for git-branches tool operations in ParameterValidator.
    'git-branches': [], // All branch operations are local for now
    'git-issues': ['create', 'list', 'get', 'update', 'close', 'comment', 'search'],
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It does well by explicitly mentioning 'safety warnings for destructive operations like branch deletion' which informs about the permanent nature of delete operations. However, it doesn't cover other important behaviors like whether operations require authentication, rate limits, what happens during merge conflicts, or the format of comparison results. The warning about destructive operations is valuable but incomplete.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with two sentences that efficiently convey the tool's scope and safety considerations. The first sentence establishes the purpose and supported operations, while the second adds important behavioral context about destructive operations. No wasted words, though it could be slightly more structured by separating operations from warnings.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 13 parameters and no output schema, the description provides adequate but incomplete context. It covers the tool's scope and warns about destructive operations, but doesn't explain return formats, error conditions, or how the six different actions relate to parameter requirements. With no annotations and no output schema, the description should ideally provide more guidance about what to expect from different operations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 13 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema - it mentions the six action types but doesn't explain parameter dependencies or usage patterns. With high schema coverage, the baseline is 3 even without additional parameter semantics in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states this is a 'Git branch management tool for branch lifecycle operations' and lists the specific operations (create, list, get, delete, merge, compare). It distinguishes from siblings by focusing specifically on branch operations rather than other Git functions like analytics, issues, or tags. However, it doesn't explicitly differentiate from similar tools like git-reset or git-workflow that might also involve branch operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for branch lifecycle operations but doesn't provide explicit guidance on when to choose this tool over alternatives. It mentions 'safety warnings for destructive operations' which hints at caution for delete operations, but doesn't specify when to use this versus other Git tools like git-reset for branch manipulation or git-remote for remote branch operations. No explicit alternatives or exclusions are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Andre-Buzeli/git-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server