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
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Project ID or URL-encoded path | |
| branch | Yes | Name for the new branch | |
| ref | No | Source branch/commit for new branch |
Implementation Reference
- src/api/branches.ts:5-24 (handler)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) }, - src/schemas.ts:284-288 (schema)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") });