Skip to main content
Glama

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
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
branch_nameYesThe name of the branch to checkout
start_pointNoStarting point for the branch (optional)
createNoWhether to create a new branch

Implementation Reference

  • 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, }; } }
  • 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,
  • Re-export of the handler from branch-operations.js in the handlers index module, making it available for import in server.js.
    handleGitCheckoutBranch,
  • Alias registration allowing 'git_checkout' as an alternative name for the git_checkout_branch tool.
    git_checkout: "git_checkout_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/bsreeram08/git-commands-mcp'

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