git_checkout_branch
Switch to or create a Git branch in a local repository to manage code changes and isolate development work.
Instructions
Create and/or checkout a branch.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes | The path to the local Git repository | |
| branch_name | Yes | The name of the branch to checkout | |
| start_point | No | Starting point for the branch (optional) | |
| create | No | Whether to create a new branch |
Implementation Reference
- src/handlers/branch-operations.js:87-156 (handler)The core handler function that executes the git checkout branch logic using simpleGit. 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-186 (schema)The input schema definition for the git_checkout_branch tool, including parameters, descriptions, and validation rules.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 main handlersMap object used by the MCP server to dispatch tool calls.git_checkout_branch: handleGitCheckoutBranch,
- src/handlers/index.js:56-56 (registration)Re-export of the handler from branch-operations.js in the handlers index module, making it available for import in server.js.handleGitCheckoutBranch,
- src/server.js:890-890 (helper)Alias registration allowing 'git_checkout' as an alternative name for the git_checkout_branch tool.git_checkout: "git_checkout_branch",