Skip to main content
Glama

checkout

Switch branches or restore working tree files in a Git repository by specifying a branch name, commit hash, or file path. Use with the Git MCP Server for enhanced Git operations.

Instructions

Switch branches or restore working tree files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoPath to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo)
targetYesBranch name, commit hash, or file path

Implementation Reference

  • Registers the 'checkout' MCP tool with name, description, and JSON input schema defining 'path' (optional) and 'target' (required).
    { name: 'checkout', description: 'Switch branches or restore working tree files', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to repository. ${PATH_DESCRIPTION}`, }, target: { type: 'string', description: 'Branch name, commit hash, or file path', }, }, required: ['target'], },
  • Core handler function that executes 'git checkout {target}' after validating the repository path and ensuring a clean working tree. Returns formatted success message with output.
    static async checkout({ path, target }: CheckoutOptions, context: GitToolContext): Promise<GitToolResult> { const resolvedPath = this.getPath({ path }); return await this.executeOperation( context.operation, resolvedPath, async () => { const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath); await RepositoryValidator.ensureClean(repoPath, context.operation); const result = await CommandExecutor.executeGitCommand( `checkout ${target}`, context.operation, repoPath ); return { content: [{ type: 'text', text: `Switched to '${target}' successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'checkout', invalidateCache: true, // Invalidate branch and status caches stateType: RepoStateType.BRANCH } );
  • TypeScript interface defining input parameters for checkout: optional path and required target.
    export interface CheckoutOptions extends GitOptions, BasePathOptions { target: string; }
  • Type guard function to validate if arguments match CheckoutOptions.
    export function isCheckoutOptions(obj: any): obj is CheckoutOptions { return obj && validatePath(obj.path) && typeof obj.target === 'string'; }
  • Dispatch handler in MCP tool executor that validates arguments and delegates to GitOperations.checkout.
    case 'checkout': { const validArgs = this.validateArguments(operation, args, isCheckoutOptions); return await GitOperations.checkout(validArgs, context); }

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/Sheshiyer/git-mcp-v2'

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