Skip to main content
Glama

git_checkout

Switch between Git branches in a repository to manage development workflows and isolate changes.

Instructions

Switches branches

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes
branch_nameYes

Implementation Reference

  • The main handler function that executes the git checkout by validating the branch name and calling repo.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}'"
  • Pydantic BaseModel defining the input schema for the git_checkout tool: repo_path and branch_name.
    class GitCheckout(BaseModel): repo_path: str branch_name: str
  • Registration of the 'git_checkout' tool in the list_tools() function using name=GitTools.CHECKOUT and the GitCheckout schema.
    Tool( name=GitTools.CHECKOUT, description="Switches branches", inputSchema=GitCheckout.model_json_schema(), ),
  • Enum definition mapping GitTools.CHECKOUT to the tool name string 'git_checkout'.
    CHECKOUT = "git_checkout"
  • Dispatch in call_tool() that invokes the git_checkout handler and returns the result as TextContent.
    case GitTools.CHECKOUT: result = git_checkout(repo, arguments["branch_name"]) return [TextContent( type="text", text=result )]

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