← Back to Skills Marketplace
zxfcn

batch-git-url-replace

by zxfcn · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
182
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install batch-git-url-replace
Description
批量替换指定目录下所有 Git 仓库的远程地址(remote URL)。 当用户需要将 Git 仓库从一个服务器迁移到另一个服务器时使用。 触发词:git remote 替换、git url 批量修改、git 仓库迁移、更换 git 地址、批量修改 remote url。
README (SKILL.md)

批量替换 Git 远程地址

输入参数

执行前必须从用户处获取以下参数:

  • scanDir:扫描目录路径(如 D:\ 或 /home/user/projects)
  • oldUrl:旧 Git 服务器地址
  • newUrl:新 Git 服务器地址

执行步骤

Windows 系统

使用 PowerShell 执行以下命令(将参数替换为用户提供的实际值):

$scanDir = "\x3CscanDir>"
$oldUrl = "\x3ColdUrl>"
$newUrl = "\x3CnewUrl>"

Write-Host "开始扫描 $scanDir 下的所有 .git/config 文件..." -ForegroundColor Cyan
Write-Host "目标:将 $oldUrl 替换为 $newUrl" -ForegroundColor Cyan
Write-Host "----------------------------------------"

$gitDirs = Get-ChildItem -Path $scanDir -Recurse -Directory -Filter ".git" -Force -ErrorAction SilentlyContinue

$countSuccess = 0
$countSkip = 0

foreach ($gitDir in $gitDirs) {
    $configPath = Join-Path $gitDir.FullName "config"
    if (Test-Path $configPath) {
        try {
            $content = Get-Content -Path $configPath -Raw -Encoding UTF8
            if ($content -like "*$oldUrl*") {
                $newContent = $content -replace [regex]::Escape($oldUrl), $newUrl
                Set-Content -Path $configPath -Value $newContent -Encoding UTF8 -NoNewline
                Write-Host "[已修改] $configPath" -ForegroundColor Green
                $countSuccess++
            } else {
                $countSkip++
            }
        } catch {
            Write-Host "[错误] 无法处理 $configPath : $_" -ForegroundColor Red
        }
    }
}

Write-Host "----------------------------------------"
Write-Host "处理完成!成功: $countSuccess, 跳过: $countSkip" -ForegroundColor Yellow

Linux 系统

使用 Bash 执行以下命令:

SCAN_DIR="\x3CscanDir>"
OLD_URL="\x3ColdUrl>"
NEW_URL="\x3CnewUrl>"

echo "开始扫描 $SCAN_DIR 下的所有 .git/config 文件..."
echo "目标:将 $OLD_URL 替换为 $NEW_URL"
echo "----------------------------------------"

count_success=0
count_skip=0

while IFS= read -r gitdir; do
    config="$gitdir/config"
    if [ -f "$config" ] && grep -q "$OLD_URL" "$config" 2>/dev/null; then
        sed -i "s|${OLD_URL}|${NEW_URL}|g" "$config"
        echo "[已修改] $config"
        ((count_success++))
    else
        ((count_skip++))
    fi
done \x3C \x3C(find "$SCAN_DIR" -name ".git" -type d 2>/dev/null)

echo "----------------------------------------"
echo "处理完成!成功: $count_success, 跳过: $count_skip"

执行后

建议用户进入某个项目目录运行 git remote -v 验证是否生效。

Usage Guidance
This skill does what it says — it scans directories and edits .git/config files in place. Before running it: (1) limit scanDir to a narrow path (not root) to avoid wide changes; (2) run tests first (copy a repo or perform a manual dry-run) because the SKILL.md provides no dry-run option; (3) back up .git/config files or your repositories first; (4) be careful with OLD_URL/NEW_URL quoting — the provided Bash sed command may misbehave with special characters or on macOS (BSD sed) and the PowerShell script uses regex replacement semantics; (5) prefer using git remote set-url per-repo if you want safer, repo-aware updates; and (6) verify results with git remote -v after changes. If you want stronger safety, ask the skill author to add a dry-run mode, automatic backups, and more robust escaping/validation.
Capability Analysis
Type: OpenClaw Skill Name: batch-git-url-replace Version: 1.0.0 The skill provides PowerShell and Bash scripts to automate the batch replacement of Git remote URLs in a specified directory. The logic in SKILL.md is transparent, aligns with the stated purpose of migrating Git repositories, and uses standard system commands (find, sed, Get-ChildItem) without any evidence of malicious intent, data exfiltration, or obfuscation.
Capability Assessment
Purpose & Capability
Name/description and runtime instructions align: the SKILL.md explicitly scans for .git directories and edits .git/config to replace remote URLs. No unrelated credentials, binaries, or installs are requested.
Instruction Scope
Instructions directly traverse the filesystem and overwrite .git/config files under the user-supplied scanDir — this is necessary for the stated task but can be dangerous if scanDir is too broad (e.g., root) or if the provided OLD_URL/NEW_URL are imprecise. There is no dry-run, no automatic backup, and minimal validation or escaping of special characters (the Bash sed usage and quoting may break or do unintended replacements for URLs containing delimiters or regex metacharacters).
Install Mechanism
Instruction-only skill with no install spec and no third-party downloads — lowest risk from install mechanisms.
Credentials
No environment variables, credentials, or config paths are requested. The skill only asks for user-provided parameters (scanDir, oldUrl, newUrl), which is proportional to its purpose.
Persistence & Privilege
always is false and the skill has no install/privilege escalation behavior. It doesn't request persistent system presence or modify other skills' configs.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install batch-git-url-replace
  3. After installation, invoke the skill by name or use /batch-git-url-replace
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release of batch-git-url-replace - Supports batch replacement of remote URLs for all Git repositories under a specified directory. - Provides step-by-step instructions and ready-to-use scripts for both Windows (PowerShell) and Linux (Bash). - Requires users to input scan directory, old URL, and new URL for operation. - Logs modified and skipped repositories and summarizes the results. - Recommends validating remote URL changes with git remote -v after execution.
Metadata
Slug batch-git-url-replace
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is batch-git-url-replace?

批量替换指定目录下所有 Git 仓库的远程地址(remote URL)。 当用户需要将 Git 仓库从一个服务器迁移到另一个服务器时使用。 触发词:git remote 替换、git url 批量修改、git 仓库迁移、更换 git 地址、批量修改 remote url。 It is an AI Agent Skill for Claude Code / OpenClaw, with 182 downloads so far.

How do I install batch-git-url-replace?

Run "/install batch-git-url-replace" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is batch-git-url-replace free?

Yes, batch-git-url-replace is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does batch-git-url-replace support?

batch-git-url-replace is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created batch-git-url-replace?

It is built and maintained by zxfcn (@zxfcn); the current version is v1.0.0.

💬 Comments