batch-git-url-replace

批量替换指定目录下所有 Git 仓库的远程地址(remote URL)。 当用户需要将 Git 仓库从一个服务器迁移到另一个服务器时使用。 触发词:git remote 替换、git url 批量修改、git 仓库迁移、更换 git 地址、批量修改 remote url。

MIT-0 · Free to use, modify, and redistribute. No attribution required.
0 · 56 · 0 current installs · 0 all-time installs
MIT-0
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
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.
Assessment
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.

Like a lobster shell, security has layers — review code before you run it.

Current versionv1.0.0
Download zip
latestvk974w4wstt9jcm1tx6a2g2cmbx8347mv

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

SKILL.md

批量替换 Git 远程地址

输入参数

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

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

执行步骤

Windows 系统

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

$scanDir = "<scanDir>"
$oldUrl = "<oldUrl>"
$newUrl = "<newUrl>"

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="<scanDir>"
OLD_URL="<oldUrl>"
NEW_URL="<newUrl>"

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 < <(find "$SCAN_DIR" -name ".git" -type d 2>/dev/null)

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

执行后

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

Files

1 total
Select a file
Select a file to preview.

Comments

Loading comments…