Skip to main content
Glama

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

Implementation Reference

  • 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, }; } }
  • 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",
  • Re-export of the handler from branch-operations.js in the handlers index for centralized imports.
    handleGitCheckoutBranch,

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