Skip to main content
Glama

git_branch

List local, remote, or all Git branches in a repository, optionally filtering by commit history to manage branch visibility.

Instructions

List Git branches

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the Git repository.
branch_typeYesWhether to list local branches ('local'), remote branches ('remote') or all branches('all').
containsNoThe commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified
not_containsNoThe commit sha that branch should NOT contain. Do not pass anything to this param if no commit sha is specified

Implementation Reference

  • The core handler function for the 'git_branch' tool. It uses GitPython's repo.git.branch() to list branches filtered by type (local, remote, all), --contains, and --no-contains commit SHAs.
    def git_branch(repo: git.Repo, branch_type: str, contains: str | None = None, not_contains: str | None = None) -> str: match contains: case None: contains_sha = (None,) case _: contains_sha = ("--contains", contains) match not_contains: case None: not_contains_sha = (None,) case _: not_contains_sha = ("--no-contains", not_contains) match branch_type: case 'local': b_type = None case 'remote': b_type = "-r" case 'all': b_type = "-a" case _: return f"Invalid branch type: {branch_type}" # None value will be auto deleted by GitPython branch_info = repo.git.branch(b_type, *contains_sha, *not_contains_sha) return branch_info
  • Pydantic BaseModel defining the input schema for the git_branch tool, including repo_path, branch_type, contains, and not_contains fields.
    class GitBranch(BaseModel): repo_path: str = Field( ..., description="The path to the Git repository.", ) branch_type: str = Field( ..., description="Whether to list local branches ('local'), remote branches ('remote') or all branches('all').", ) contains: Optional[str] = Field( None, description="The commit sha that branch should contain. Do not pass anything to this param if no commit sha is specified", ) not_contains: Optional[str] = Field( None, description="The commit sha that branch should NOT contain. Do not pass anything to this param if no commit sha is specified", )
  • Registration of the 'git_branch' tool in the server's list_tools() method, providing name, description, and input schema.
    Tool( name=GitTools.BRANCH, description="List Git branches", inputSchema=GitBranch.model_json_schema(), )
  • Dispatch logic in the call_tool handler that matches on GitTools.BRANCH and invokes the git_branch function with parsed arguments.
    case GitTools.BRANCH: result = git_branch( repo, arguments.get("branch_type", 'local'), arguments.get("contains", None), arguments.get("not_contains", None), ) return [TextContent( type="text", text=result )]
  • Enum constant defining the tool name 'git_branch' in GitTools.
    BRANCH = "git_branch"

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