git_branch
List, create, or switch Git branches in a repository. Specify action and branch name to manage version control workflows.
Instructions
List, create, or switch branches
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action to perform | |
| name | No | Branch name (for create/switch) | |
| cwd | No | Repository path |
Implementation Reference
- src/services/GitService.ts:304-338 (handler)The gitBranch handler method: delegates based on action (list, create, switch, delete, merge, rebase) and runs the corresponding git command via gitCommand.
async gitBranch(args: GitBranchArgs): Promise<ToolResult> { const { action, name, force, cwd } = args; ValidationUtils.validateRequired({ action }, ['action']); let branchArgs: string[]; switch (action) { case GIT_ACTIONS.LIST: branchArgs = ['branch', '-a']; break; case GIT_ACTIONS.CREATE: if (!name) throw new Error('Branch name required for create action'); branchArgs = ['checkout', '-b', name]; break; case GIT_ACTIONS.SWITCH: if (!name) throw new Error('Branch name required for switch action'); branchArgs = ['checkout', name]; break; case GIT_ACTIONS.DELETE: if (!name) throw new Error('Branch name required for delete action'); branchArgs = ['branch', force ? '-D' : '-d', name]; break; case GIT_ACTIONS.MERGE: if (!name) throw new Error('Branch name required for merge action'); branchArgs = ['merge', name]; break; case GIT_ACTIONS.REBASE: if (!name) throw new Error('Branch name required for rebase action'); branchArgs = ['rebase', name]; break; default: throw new Error(`Unknown git branch action: ${action}`); } return await this.gitCommand(branchArgs, cwd); } - src/services/GitService.ts:43-47 (schema)GitBranchArgs interface: defines the schema with action (required), name, force, and cwd fields.
export interface GitBranchArgs extends GitCommandArgs { action: GitAction; name?: string; force?: boolean; } - src/index.ts:197-198 (registration)Registration in the tool dispatcher: routes 'git_branch' to gitService.gitBranch.
case 'git_branch': return await this.gitService.gitBranch(args as GitBranchArgs); - src/toolDefinitions.ts:297-309 (registration)Tool definition registration: declares the 'git_branch' tool with name, description, and input schema.
{ name: 'git_branch', description: 'List, create, or switch branches', inputSchema: { type: 'object', properties: { action: { type: 'string', description: 'Action to perform' }, name: { type: 'string', description: 'Branch name (for create/switch)' }, cwd: { type: 'string', description: 'Repository path' }, }, required: ['action'], }, }, - src/constants.ts:39-46 (helper)GIT_ACTIONS constant: defines valid actions (list, create, switch, delete, merge, rebase) used by the gitBranch handler.
export const GIT_ACTIONS = { LIST: 'list', CREATE: 'create', SWITCH: 'switch', DELETE: 'delete', MERGE: 'merge', REBASE: 'rebase', } as const;