push
Push commits and tags to a remote Git repository, optionally force-pushing changes or skipping pre-push hooks, using the Git MCP Server for enhanced Git operations.
Instructions
Push commits to remote
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | Yes | Branch name | |
| force | No | Force push changes | |
| noVerify | No | Skip pre-push hooks | |
| path | No | Path to repository. MUST be an absolute path (e.g., /Users/username/projects/my-repo) | |
| remote | No | Remote name | origin |
| tags | No | Push all tags |
Implementation Reference
- src/git-operations.ts:257-286 (handler)Primary handler function for the 'push' tool. Validates inputs, executes 'git push' command with options, handles caching and errors.static async push({ path, remote = 'origin', branch, force, noVerify, tags }: PushPullOptions, context: GitToolContext): Promise<GitToolResult> { const resolvedPath = this.getPath({ path }); return await this.executeOperation( context.operation, resolvedPath, async () => { const { path: repoPath } = PathValidator.validateGitRepo(resolvedPath); await RepositoryValidator.validateRemoteConfig(repoPath, remote, context.operation); await RepositoryValidator.validateBranchExists(repoPath, branch, context.operation); const result = await CommandExecutor.executeGitCommand( `push ${remote} ${branch}${force ? ' --force' : ''}${noVerify ? ' --no-verify' : ''}${tags ? ' --tags' : ''}`, context.operation, repoPath ); return { content: [{ type: 'text', text: `Changes pushed successfully\n${CommandExecutor.formatOutput(result)}` }] }; }, { command: 'push', invalidateCache: true, // Invalidate remote cache stateType: RepoStateType.REMOTE } ); }
- src/tool-handler.ts:156-193 (registration)Registers the 'push' tool in the MCP server's ListTools handler, defining name, description, and input schema.{ name: 'push', description: 'Push commits to remote', inputSchema: { type: 'object', properties: { path: { type: 'string', description: `Path to repository. ${PATH_DESCRIPTION}`, }, remote: { type: 'string', description: 'Remote name', default: 'origin', }, branch: { type: 'string', description: 'Branch name', }, force: { type: 'boolean', description: 'Force push changes', default: false }, noVerify: { type: 'boolean', description: 'Skip pre-push hooks', default: false }, tags: { type: 'boolean', description: 'Push all tags', default: false } }, required: ['branch'], }, },
- src/types.ts:66-72 (schema)TypeScript interface defining the input parameters for push/pull operations, used for type checking and validation.export interface PushPullOptions extends GitOptions, BasePathOptions { remote?: string; branch: string; force?: boolean; // Allow force push/pull noVerify?: boolean; // Skip pre-push/pre-pull hooks tags?: boolean; // Include tags }
- src/tool-handler.ts:593-596 (handler)Dispatches 'push' tool calls to GitOperations.push after argument validation.case 'push': { const validArgs = this.validateArguments(operation, args, isPushPullOptions); return await GitOperations.push(validArgs, context); }
- src/types.ts:164-168 (schema)Type guard function used to validate push/pull options before execution.export function isPushPullOptions(obj: any): obj is PushPullOptions { return obj && validatePath(obj.path) && typeof obj.branch === 'string'; }