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
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"target": "<target>"
},
"name": "checkout"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo) | |
| target | Yes | Branch name, commit hash, or file path |
Implementation Reference
- src/tool-handler.ts:282-298 (registration)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'], }, - src/git-operations.ts:471-498 (handler)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 } ); - src/types.ts:81-83 (schema)TypeScript interface defining input parameters for checkout: optional path and required target.
export interface CheckoutOptions extends GitOptions, BasePathOptions { target: string; } - src/types.ts:176-180 (schema)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'; } - src/tool-handler.ts:618-621 (handler)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); }