git_checkout_branch
Switch to or create a Git branch in a local repository. Specify the repository path and branch name, with an optional starting point for new branches.
Instructions
Create and/or checkout a branch.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch_name | Yes | The name of the branch to checkout | |
| create | No | Whether to create a new branch | |
| repo_path | Yes | The path to the local Git repository | |
| start_point | No | Starting point for the branch (optional) |
Implementation Reference
- src/handlers/branch-operations.js:87-156 (handler)The core handler function implementing git checkout/create branch logic using simpleGit library. Handles both creating new branches and switching to existing ones.export async function handleGitCheckoutBranch({ repo_path, branch_name, start_point = null, create = false, }) { try { const git = simpleGit(repo_path); if (create) { // Create and checkout a new branch if (start_point) { await git.checkoutBranch(branch_name, start_point); } else { await git.checkoutLocalBranch(branch_name); } return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Created and checked out new branch: ${branch_name}`, branch: branch_name, }, null, 2 ), }, ], }; } else { // Just checkout an existing branch await git.checkout(branch_name); return { content: [ { type: "text", text: JSON.stringify( { success: true, message: `Checked out branch: ${branch_name}`, branch: branch_name, }, null, 2 ), }, ], }; } } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to checkout branch: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
- src/server.js:161-185 (schema)Tool schema definition including input parameters validation (repo_path, branch_name, start_point, create) for the git_checkout_branch tool.name: "git_checkout_branch", description: "Create and/or checkout a branch.", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, branch_name: { type: "string", description: "The name of the branch to checkout", }, start_point: { type: "string", description: "Starting point for the branch (optional)", }, create: { type: "boolean", description: "Whether to create a new branch", default: false, }, }, required: ["repo_path", "branch_name"], },
- src/server.js:909-909 (registration)Registration of the handler function in the central handlersMap object used by the MCP server to route tool calls.git_checkout_branch: handleGitCheckoutBranch,
- src/server.js:890-890 (registration)Alias registration mapping 'git_checkout' to 'git_checkout_branch' for user-friendly tool invocation.git_checkout: "git_checkout_branch",
- src/handlers/index.js:56-56 (registration)Re-export of the handler from branch-operations.js in the handlers index for centralized imports.handleGitCheckoutBranch,