Skip to main content
Glama

create_branch

Create a new branch in a GitLab project by specifying the project ID, branch name, and source reference for version control workflows.

Instructions

Create a new branch in a GitLab project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesProject ID or URL-encoded path
branchYesName for the new branch
refNoSource branch/commit for new branch

Implementation Reference

  • The actual implementation of the branch creation logic, utilizing the gitlab-client to perform the API call.
    export async function createBranch(projectId: string, options: CreateBranchOptions): Promise<GitLabReference> {
      if (!projectId?.trim()) {
        throw new Error("Project ID is required");
      }
      if (!options.name?.trim()) {
        throw new Error("Branch name is required");
      }
      if (!options.ref?.trim()) {
        throw new Error("Source reference is required");
      }
    
      const endpoint = `/projects/${encodeProjectId(projectId)}/repository/branches`;
    
      const branch = await gitlabPost<GitLabReference>(endpoint, {
        branch: options.name,
        ref: options.ref
      });
    
      return GitLabReferenceSchema.parse(branch);
    }
  • src/server.ts:227-235 (registration)
    The tool request handler switch-case block where the `create_branch` request is handled.
    case "create_branch": {
      const args = CreateBranchSchema.parse(request.params.arguments);
      const ref = args.ref || "HEAD";
      const branch = await api.createBranch(args.project_id, {
        name: args.branch,
        ref
      });
      return { content: [{ type: "text", text: JSON.stringify(branch, null, 2) }] };
    }
  • src/server.ts:104-108 (registration)
    The definition of the `create_branch` tool including its name, description, and input schema.
    {
      name: "create_branch",
      description: "Create a new branch in a GitLab project",
      inputSchema: zodToJsonSchema(CreateBranchSchema)
    },
  • The Zod schema definition for input validation of the `create_branch` tool.
    export const CreateBranchSchema = ProjectParamsSchema.extend({
      branch: z.string().describe("Name for the new branch"),
      ref: z.string().optional().describe("Source branch/commit for new branch")
    });

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/TheRealChrisThomas/gitlab-mcp-server'

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