git_push
Push Git commits to remote repositories to synchronize local changes with team members and deployment environments.
Instructions
Push commits to remote repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Repository directory | |
| remote | No | Remote name | origin |
| branch | No | Branch to push (defaults to current branch) | |
| force | No | Force push (use with caution) | |
| setUpstream | No | Set upstream tracking |
Implementation Reference
- src/tools/git.ts:295-300 (handler)The gitPush function implements the core logic for the git_push tool by constructing and executing the appropriate git push command using the shared executeGitCommand helper.export async function gitPush(args: z.infer<typeof gitPushSchema>): Promise<ToolResponse> { const forceFlag = args.force ? '--force' : ''; const upstreamFlag = args.setUpstream ? '-u' : ''; const branch = args.branch || ''; return executeGitCommand(`git push ${upstreamFlag} ${forceFlag} ${args.remote} ${branch}`.trim(), args.cwd); }
- src/tools/git.ts:120-126 (schema)Zod schema used for input validation of git_push tool arguments in the handler dispatch.export const gitPushSchema = z.object({ cwd: z.string().optional().describe('Repository directory'), remote: z.string().optional().default('origin').describe('Remote name'), branch: z.string().optional().describe('Branch to push (defaults to current branch)'), force: z.boolean().optional().default(false).describe('Force push (use with caution)'), setUpstream: z.boolean().optional().default(false).describe('Set upstream tracking') });
- src/index.ts:389-392 (registration)Registration and dispatch logic in the main MCP server handler that routes 'git_push' calls to the gitPush function after validation.if (name === 'git_push') { const validated = gitPushSchema.parse(args); return await gitPush(validated); }
- src/tools/git.ts:603-616 (schema)MCP-compatible JSON schema definition for the git_push tool, included in the gitTools array returned by listTools.{ name: 'git_push', description: 'Push commits to remote repository', inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Repository directory' }, remote: { type: 'string', default: 'origin', description: 'Remote name' }, branch: { type: 'string', description: 'Branch to push (defaults to current branch)' }, force: { type: 'boolean', default: false, description: 'Force push (use with caution)' }, setUpstream: { type: 'boolean', default: false, description: 'Set upstream tracking' } } } },
- src/tools/git.ts:21-61 (helper)Shared helper function executeGitCommand that all git tools (including gitPush) use to run git commands and format responses.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 }; } }