Skip to main content
Glama
ConnorBoetig-dev

Unrestricted Development MCP Server

git_checkout

Switch between Git branches, restore files to specific versions, or create new branches to manage your code changes and repository state.

Instructions

Switch branches or restore files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetYesBranch name, commit hash, or file path to checkout
cwdNoRepository directory
createBranchNoCreate new branch
forceNoForce checkout, discarding local changes

Implementation Reference

  • The main handler function that constructs and executes the 'git checkout' command using the shared executeGitCommand helper, handling branch creation and force flags.
    export async function gitCheckout(args: z.infer<typeof gitCheckoutSchema>): Promise<ToolResponse> { const createFlag = args.createBranch ? '-b' : ''; const forceFlag = args.force ? '-f' : ''; return executeGitCommand(`git checkout ${createFlag} ${forceFlag} ${args.target}`.trim(), args.cwd); }
  • Zod schema defining the input parameters and validation for the git_checkout tool.
    export const gitCheckoutSchema = z.object({ target: z.string().describe('Branch name, commit hash, or file path to checkout'), cwd: z.string().optional().describe('Repository directory'), createBranch: z.boolean().optional().default(false).describe('Create new branch'), force: z.boolean().optional().default(false).describe('Force checkout, discarding local changes') });
  • MCP tool registration entry in gitTools array, defining the tool name, description, and JSON input schema for protocol listing.
    { name: 'git_checkout', description: 'Switch branches or restore files', inputSchema: { type: 'object', properties: { target: { type: 'string', description: 'Branch name, commit hash, or file path to checkout' }, cwd: { type: 'string', description: 'Repository directory' }, createBranch: { type: 'boolean', default: false, description: 'Create new branch' }, force: { type: 'boolean', default: false, description: 'Force checkout, discarding local changes' } }, required: ['target'] } },
  • src/index.ts:381-384 (registration)
    Server request handler dispatcher that matches tool name 'git_checkout', validates arguments, and invokes the gitCheckout handler.
    if (name === 'git_checkout') { const validated = gitCheckoutSchema.parse(args); return await gitCheckout(validated); }
  • Shared helper utility that executes git shell commands asynchronously, handles output/error formatting, and returns standardized ToolResponse.
    async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024 // 10MB buffer }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }

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/ConnorBoetig-dev/mcp2'

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