git_init
Initialize a new git repository in any directory to start tracking code changes and manage version control for your development projects.
Instructions
Initialize a new git repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Directory to initialize as git repository | |
| bare | No | Create bare repository |
Implementation Reference
- src/tools/git.ts:309-312 (handler)The handler function that executes the 'git init' command, constructing the command with optional --bare flag and calling the shared executeGitCommand helper.export async function gitInit(args: z.infer<typeof gitInitSchema>): Promise<ToolResponse> { const bareFlag = args.bare ? '--bare' : ''; return executeGitCommand(`git init ${bareFlag}`.trim(), args.cwd); }
- src/tools/git.ts:136-139 (schema)Zod schema defining the input parameters for the gitInit handler: optional cwd and bare boolean.export const gitInitSchema = z.object({ cwd: z.string().optional().describe('Directory to initialize as git repository'), bare: z.boolean().optional().default(false).describe('Create bare repository') });
- src/tools/git.ts:632-642 (registration)MCP tool registration object within gitTools array, defining name, description, and JSON schema for 'git_init'.{ name: 'git_init', description: 'Initialize a new git repository', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Directory to initialize as git repository' }, bare: { type: 'boolean', default: false, description: 'Create bare repository' } } } },
- src/index.ts:397-400 (registration)Dispatch logic in main MCP server handler that matches tool name 'git_init', validates args with gitInitSchema, and calls gitInit function.if (name === 'git_init') { const validated = gitInitSchema.parse(args); return await gitInit(validated); }
- src/tools/git.ts:21-61 (helper)Shared helper function used by all git tools, including gitInit, to execute git commands via child_process.exec and format ToolResponse.async function executeGitCommand(command: string, cwd?: string): Promise<ToolResponse> { try { const { stdout, stderr } = await execAsync(command, { cwd: cwd || process.cwd(), shell: '/bin/bash', maxBuffer: 10 * 1024 * 1024 // 10MB buffer }); return { content: [ { type: "text" as const, text: JSON.stringify({ success: true, command: command, stdout: stdout.trim(), stderr: stderr.trim(), cwd: cwd || process.cwd() }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: "text" as const, text: JSON.stringify({ success: false, command: command, stdout: error.stdout?.trim() || '', stderr: error.stderr?.trim() || error.message, exitCode: error.code || 1, cwd: cwd || process.cwd() }, null, 2) } ], isError: true }; } }