Skip to main content
Glama

branch_create

Create a new branch in a specified Git repository using the Git MCP Server. Input branch name and repository path; optionally force creation, set tracking, or configure upstream for push/pull operations.

Instructions

Create a new branch

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
forceNoForce create branch even if it exists
nameYesBranch name
pathNoPath to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)
setUpstreamNoSet upstream for push/pull
trackNoSet up tracking mode

Implementation Reference

  • The primary handler function for 'branch_create' tool. Validates repository and branch name, executes 'git checkout -b' command with flags for force, track, and setUpstream, handles caching invalidation for branch state, and returns formatted success message.
    static async branchCreate({ path, name, force, track, setUpstream }: 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);
          
          const result = await CommandExecutor.executeGitCommand(
            `checkout -b ${name}${force ? ' --force' : ''}${track ? ' --track' : ' --no-track'}${setUpstream ? ' --set-upstream' : ''}`,
            context.operation,
            repoPath
          );
    
          return {
            content: [{
              type: 'text',
              text: `Branch '${name}' created successfully\n${CommandExecutor.formatOutput(result)}`
            }]
          };
        },
        {
          command: 'branch_create',
          invalidateCache: true, // Invalidate branch cache
          stateType: RepoStateType.BRANCH
        }
      );
    }
  • MCP tool registration for 'branch_create', defining the tool name, description, input schema with properties for path, name, force, track, setUpstream, and required fields.
    {
      name: 'branch_create',
      description: 'Create a new branch',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: `Path to repository. ${PATH_DESCRIPTION}`,
          },
          name: {
            type: 'string',
            description: 'Branch name',
          },
          force: {
            type: 'boolean',
            description: 'Force create branch even if it exists',
            default: false
          },
          track: {
            type: 'boolean',
            description: 'Set up tracking mode',
            default: true
          },
          setUpstream: {
            type: 'boolean',
            description: 'Set upstream for push/pull',
            default: false
          }
        },
        required: ['name'],
      },
  • Tool dispatch handler in switch statement that validates arguments using isBranchOptions type guard and calls GitOperations.branchCreate.
    case 'branch_create': {
      const validArgs = this.validateArguments(operation, args, isBranchOptions);
      return await GitOperations.branchCreate(validArgs, context);
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related 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/Sheshiyer/git-mcp-v2'

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