Skip to main content
Glama

git_clean

Remove untracked files and directories from a Git repository to clean up workspace clutter. Specify repository path, directory removal, force options, or dry run to preview changes.

Instructions

Perform git clean operations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYesThe path to the local Git repository
directoriesNoWhether to remove directories as well
forceNoWhether to force clean
dry_runNoWhether to perform a dry run

Implementation Reference

  • Implements the git clean tool logic using simpleGit. Supports dry-run previews, force removal, and directory cleaning with safety checks.
    export async function handleGitClean({ repo_path, directories = false, force = false, dry_run = true, }) { try { const git = simpleGit(repo_path); // At least one of force or dry_run must be true for safety if (!force && !dry_run) { return { content: [ { type: "text", text: JSON.stringify( { error: "For safety, either force or dry_run must be true" }, null, 2 ), }, ], isError: true, }; } // Build the clean command const cleanOptions = []; if (directories) { cleanOptions.push("-d"); } if (force) { cleanOptions.push("-f"); } if (dry_run) { cleanOptions.push("-n"); } // Get the files that would be removed const preview = await git.clean([ "--dry-run", ...(directories ? ["-d"] : []), ]); const filesToRemove = preview .split("\n") .filter((line) => line.startsWith("Would remove")) .map((line) => line.replace("Would remove ", "").trim()); if (!dry_run) { // Perform the actual clean await git.clean(cleanOptions); } return { content: [ { type: "text", text: JSON.stringify( { success: true, message: dry_run ? `Would remove ${filesToRemove.length} files/directories` : `Removed ${filesToRemove.length} files/directories`, files: filesToRemove, dry_run: dry_run, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify( { error: `Failed to clean repository: ${error.message}` }, null, 2 ), }, ], isError: true, }; } }
  • Defines the input schema and metadata for the 'git_clean' tool used in tool listing and validation.
    name: "git_clean", description: "Perform git clean operations.", inputSchema: { type: "object", properties: { repo_path: { type: "string", description: "The path to the local Git repository", }, directories: { type: "boolean", description: "Whether to remove directories as well", default: false, }, force: { type: "boolean", description: "Whether to force clean", default: false, }, dry_run: { type: "boolean", description: "Whether to perform a dry run", default: true, }, }, required: ["repo_path"], }, },
  • src/server.js:922-922 (registration)
    Maps the tool name 'git_clean' to its handler function in the central handlersMap for request dispatching.
    git_clean: handleGitClean,
  • Imports the handleGitClean function from other-operations.js for re-export.
    handleGitClean,
  • src/server.js:33-38 (registration)
    Imports handleGitClean from handlers/index.js into the server for use in handlersMap.
    handleGitClean, handleGitHooks, handleGitLFS, handleGitLFSFetch, handleGitRevert, } from "./handlers/index.js";

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/bsreeram08/git-commands-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server