Skip to main content
Glama

git_branch

List, create, or switch Git branches in a repository. Specify action and branch name to manage version control workflows.

Instructions

List, create, or switch branches

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction to perform
nameNoBranch name (for create/switch)
cwdNoRepository path

Implementation Reference

  • The gitBranch handler method: delegates based on action (list, create, switch, delete, merge, rebase) and runs the corresponding git command via gitCommand.
    async gitBranch(args: GitBranchArgs): Promise<ToolResult> {
      const { action, name, force, cwd } = args;
      ValidationUtils.validateRequired({ action }, ['action']);
      
      let branchArgs: string[];
      switch (action) {
        case GIT_ACTIONS.LIST:
          branchArgs = ['branch', '-a'];
          break;
        case GIT_ACTIONS.CREATE:
          if (!name) throw new Error('Branch name required for create action');
          branchArgs = ['checkout', '-b', name];
          break;
        case GIT_ACTIONS.SWITCH:
          if (!name) throw new Error('Branch name required for switch action');
          branchArgs = ['checkout', name];
          break;
        case GIT_ACTIONS.DELETE:
          if (!name) throw new Error('Branch name required for delete action');
          branchArgs = ['branch', force ? '-D' : '-d', name];
          break;
        case GIT_ACTIONS.MERGE:
          if (!name) throw new Error('Branch name required for merge action');
          branchArgs = ['merge', name];
          break;
        case GIT_ACTIONS.REBASE:
          if (!name) throw new Error('Branch name required for rebase action');
          branchArgs = ['rebase', name];
          break;
        default:
          throw new Error(`Unknown git branch action: ${action}`);
      }
      
      return await this.gitCommand(branchArgs, cwd);
    }
  • GitBranchArgs interface: defines the schema with action (required), name, force, and cwd fields.
    export interface GitBranchArgs extends GitCommandArgs {
      action: GitAction;
      name?: string;
      force?: boolean;
    }
  • src/index.ts:197-198 (registration)
    Registration in the tool dispatcher: routes 'git_branch' to gitService.gitBranch.
    case 'git_branch':
      return await this.gitService.gitBranch(args as GitBranchArgs);
  • Tool definition registration: declares the 'git_branch' tool with name, description, and input schema.
    {
      name: 'git_branch',
      description: 'List, create, or switch branches',
      inputSchema: {
        type: 'object',
        properties: {
          action: { type: 'string', description: 'Action to perform' },
          name: { type: 'string', description: 'Branch name (for create/switch)' },
          cwd: { type: 'string', description: 'Repository path' },
        },
        required: ['action'],
      },
    },
  • GIT_ACTIONS constant: defines valid actions (list, create, switch, delete, merge, rebase) used by the gitBranch handler.
    export const GIT_ACTIONS = {
      LIST: 'list',
      CREATE: 'create',
      SWITCH: 'switch',
      DELETE: 'delete',
      MERGE: 'merge',
      REBASE: 'rebase',
    } as const;
Behavior2/5

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

No annotations provided; description is bare. It does not disclose behavioral traits such as whether switching overwrites local changes, requires a clean working tree, or what happens during creation. The agent needs this context.

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

Conciseness3/5

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

The description is extremely concise (single line). It is not verbose, but lacks structure. Could benefit from front-loading the action list or adding context. No wasted words, but also no helpful structure.

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

Completeness2/5

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

Given the complexity of git operations and the presence of many sibling tools, this description is insufficient. It does not mention return values, error cases (e.g., switching with uncommitted changes), or how the repository path is used. The output schema is absent, so description should compensate.

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

Parameters2/5

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

Schema coverage is 100% but parameter descriptions are minimal ('Action to perform'). The description does not elaborate on possible action values (e.g., 'list', 'create', 'switch'), which would help the agent select the correct action. The description adds little beyond schema.

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 it lists, creates, or switches branches. The verb 'List, create, or switch' and resource 'branches' are specific. However, it does not differentiate from other git sibling tools like git_add or git_commit, but the name itself disambiguates.

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

Usage Guidelines2/5

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

No guidance on when to use list vs create vs switch, nor when to prefer this tool over alternative git commands. The description does not mention prerequisites or context for switching branches.

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/agentics-ai/code-mcp'

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