Skip to main content
Glama

checkout

Switch branches, commit hashes, or restore working tree files in a Git repository. Force checkout, create new branches, detach commits, or manage upstream configuration directly.

Instructions

Switch branches, commits, or restore working tree files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
createBranchNoCreate a new branch and start it at <start-point> (-b <new-branch>)
createBranchForceNoCreate or reset a branch and start it at <start-point> (-B <new-branch>)
detachNoCheck out a commit for inspection rather than switching to a branch (--detach)
forceNoForce checkout, throw away local modifications (-f, --force)
mergeNoWhen switching branches, proceed even if index/working tree differs from HEAD (-m, --merge)
noTrackNoDo not set up upstream configuration (--no-track)
orphanNoCreate a new orphan branch (--orphan <new-branch>)
pathspecNoLimit checkout to specific paths
repoPathYesAbsolute path to the git repository
targetYesBranch name, commit hash, or tag to checkout
trackNoSet up upstream configuration (--track)

Implementation Reference

  • The private #handle method implements the core logic: validates it's a git repo, transforms input to options, executes simple-git checkout, and returns success or error.
    readonly #handle: ToolCallback<typeof GIT_CHECKOUT_INPUT_SCHEMA> = async (input) => {
    	const sg = simpleGit(input.repoPath);
    
    	const isRepo = await sg.checkIsRepo();
    	if (!isRepo) {
    		return {
    			isError: true,
    			content: [
    				{
    					type: 'text',
    					text: 'Not a git repository',
    				},
    			],
    		};
    	}
    
    	// Execute checkout with transformed options and target
    	await sg.checkout(input.target, this.inputToOptions(input));
    
    	return {
    		content: [
    			{
    				type: 'text',
    				text: 'Checkout completed successfully',
    			},
    		],
    	};
    };
  • Zod input schema defining parameters for repoPath, target, force, merge, detach, branch creation options, tracking, and pathspec.
    // Git checkout input schema constant synced with git-checkout documentation
    export const GIT_CHECKOUT_INPUT_SCHEMA = {
    	repoPath: z.string().describe('Absolute path to the git repository'),
    	target: z.string().describe('Branch name, commit hash, or tag to checkout'),
    	force: z.boolean().optional().describe('Force checkout, throw away local modifications (-f, --force)'),
    	merge: z
    		.boolean()
    		.optional()
    		.describe('When switching branches, proceed even if index/working tree differs from HEAD (-m, --merge)'),
    	detach: z
    		.boolean()
    		.optional()
    		.describe('Check out a commit for inspection rather than switching to a branch (--detach)'),
    	createBranch: z.string().optional().describe('Create a new branch and start it at <start-point> (-b <new-branch>)'),
    	createBranchForce: z
    		.string()
    		.optional()
    		.describe('Create or reset a branch and start it at <start-point> (-B <new-branch>)'),
    	orphan: z.string().optional().describe('Create a new orphan branch (--orphan <new-branch>)'),
    	track: z.boolean().optional().describe('Set up upstream configuration (--track)'),
    	noTrack: z.boolean().optional().describe('Do not set up upstream configuration (--no-track)'),
    	pathspec: z.array(z.string()).optional().describe('Limit checkout to specific paths'),
    };
  • Registers the checkout tool instance with the MCP server in the main index file.
    new GitCheckoutTool().register(server);
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate readOnlyHint=false, implying this is a mutation tool, which aligns with the description's verbs ('switch', 'restore') that suggest state changes. The description adds minimal behavioral context beyond annotations—it hints at destructive potential ('restore' implies overwriting files) but doesn't detail risks like data loss from 'force' or 'merge' parameters, rate limits, or authentication needs. With annotations covering the mutation aspect, this earns a baseline score for adding some value.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. Every word earns its place by concisely covering the tool's main actions, making it easy for an agent to parse and understand quickly. There's no redundancy or fluff, adhering perfectly to conciseness standards.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (11 parameters, mutation indicated by annotations) and lack of an output schema, the description is minimally adequate but incomplete. It states what the tool does but doesn't address behavioral nuances like error conditions, side effects (e.g., working tree changes), or return values. With annotations providing some context (readOnlyHint=false), it meets a basic threshold but leaves gaps for safe and effective use by an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with each parameter well-documented in the input schema (e.g., 'force' explains it throws away local modifications). The description adds no parameter-specific semantics beyond the schema, such as clarifying interactions between parameters like 'createBranch' and 'target'. Given the high schema coverage, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('switch', 'restore') and resources ('branches', 'commits', 'working tree files'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'create-branch' or 'reset', which also involve branch/commit operations, leaving some ambiguity about when this specific tool should be chosen over alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'create-branch' (for creating branches without switching), 'reset' (for restoring files without switching), or 'log' (for inspecting commits without detaching). There's no mention of prerequisites, typical workflows, or exclusions, leaving the agent to infer usage from the purpose alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/ver0-project/mcps'

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