Skip to main content
Glama
modelcontextprotocol

git MCP server

Official

git_checkout

Switch to a specified branch in a Git repository. Provide the repository path and branch name to change the active branch.

Instructions

Switches branches

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes
branch_nameYes

Implementation Reference

  • The git_checkout function that executes the checkout logic: validates branch name, resolves the ref, and runs git checkout.
    def git_checkout(repo: git.Repo, branch_name: str) -> str:
        # Defense in depth: reject branch names starting with '-' to prevent flag injection,
        # even if a malicious ref with that name exists (e.g. via filesystem manipulation)
        if branch_name.startswith("-"):
            raise BadName(f"Invalid branch name: '{branch_name}' - cannot start with '-'")
        repo.rev_parse(branch_name)  # Validates branch_name is a real git ref, throws BadName if not
        repo.git.checkout(branch_name)
        return f"Switched to branch '{branch_name}'"
  • The GitCheckout Pydantic model defining the input schema for the git_checkout tool (repo_path and branch_name fields).
    class GitCheckout(BaseModel):
        repo_path: str
        branch_name: str
  • The enum entry CHECKOUT = 'git_checkout' that registers the tool name.
    CHECKOUT = "git_checkout"
  • The Tool registration object listing the git_checkout tool in the list_tools handler.
    Tool(
        name=GitTools.CHECKOUT,
        description="Switches branches",
        inputSchema=GitCheckout.model_json_schema(),
        annotations=ToolAnnotations(
            readOnlyHint=False,
            destructiveHint=False,
            idempotentHint=False,
            openWorldHint=False,
        ),
    ),
  • The call_tool match case that dispatches to git_checkout when the tool name is CHECKOUT.
    case GitTools.CHECKOUT:
        result = git_checkout(repo, arguments["branch_name"])
        return [TextContent(
            type="text",
            text=result
        )]
Behavior2/5

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

Annotations provide readOnlyHint=false, destructiveHint=false, idempotentHint=false, openWorldHint=false. Description adds no behavioral context beyond annotation, such as effects of uncommitted changes or merge conflicts. For a branching operation, this is a gap.

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

Conciseness3/5

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

Extremely brief (two words), which could be considered concise, but lacks structure and substance. It is front-loaded but arguably under-specified.

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

Completeness1/5

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

Given the tool's context (2 params, no output schema, simple but with side effects), the description is incomplete. It does not address what happens when switching branches (e.g., uncommitted changes, conflicts) or return value.

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

Parameters1/5

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

Schema description coverage is 0%, and description does not explain parameters. Despite 'repo_path' and 'branch_name' being somewhat self-explanatory, the description fails to add meaning beyond the schema, which itself lacks descriptions. Baseline for low coverage requires compensation; here it is absent.

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?

Description clearly states 'Switches branches', a specific verb and resource. However, it does not differentiate from sibling tools like 'git_branch' (which likely lists/create/delete branches) or 'git_create_branch', but the action is distinct enough. Score 4 for clarity but lacking sibling differentiation.

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?

No guidance on when to use this tool versus alternatives like 'git_create_branch' or 'git_branch'. No exclusions, prerequisites, or context provided.

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

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/modelcontextprotocol/git'

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