git-sync-all
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Sync All
Git 批量同步
Synchronize all git repositories under the current working directory by pulling latest changes from their remotes — using maximum parallelism.
通过从远程仓库拉取最新变更,同步当前工作目录下的所有Git仓库——采用最大并行度。
When to Use
使用场景
- After switching to a different computer
- When you need to update multiple projects at once
- To ensure all local repositories are up to date with remotes
- 更换电脑后
- 需要一次性更新多个项目时
- 确保所有本地仓库与远程仓库保持同步
Strict Execution Flow
严格执行流程
Do NOT use any scripts. Do NOT skip or merge phases. Execute each phase in order.
禁止使用任何脚本。禁止跳过或合并阶段。按顺序执行每个阶段。
Phase 1: Environment Detection (MANDATORY — must display results before proceeding)
阶段1:环境检测(必填——必须先显示结果再继续)
Detect and explicitly display the following before doing anything else:
- Operating System: Run a command to detect the OS.
- Windows: or
[System.Environment]::OSVersion$env:OS - macOS/Linux:
uname -s
- Windows:
- Shell environment: Identify the current shell.
- PowerShell:
$PSVersionTable.PSVersion - bash/zsh: and
echo $SHELLorecho $BASH_VERSIONecho $ZSH_VERSION
- PowerShell:
- Agent identity: Identify which agent is running this skill (Claude Code, GitHub Copilot CLI, Cursor, etc.) based on the agent's own context/identity.
- Git availability: Run to verify git is installed.
git --version
Display the detection results clearly, for example:
Environment Detection:
OS: Windows 11 (10.0.22631)
Shell: PowerShell 7.4
Agent: GitHub Copilot CLI
Git: git version 2.44.0.windows.1All subsequent phases MUST use ONLY commands appropriate for the detected OS and shell. Never mix platform commands.
在执行任何操作前,检测并明确显示以下信息:
- 操作系统:运行命令检测操作系统。
- Windows:或
[System.Environment]::OSVersion$env:OS - macOS/Linux:
uname -s
- Windows:
- Shell环境:识别当前使用的Shell。
- PowerShell:
$PSVersionTable.PSVersion - bash/zsh:和
echo $SHELL或echo $BASH_VERSIONecho $ZSH_VERSION
- PowerShell:
- Agent身份:根据Agent自身的上下文/身份,识别运行该技能的Agent(如Claude Code、GitHub Copilot CLI、Cursor等)。
- Git可用性:运行 验证Git是否已安装。
git --version
清晰显示检测结果,例如:
环境检测结果:
操作系统: Windows 11 (10.0.22631)
Shell: PowerShell 7.4
Agent: GitHub Copilot CLI
Git: git version 2.44.0.windows.1后续所有阶段必须仅使用适用于检测到的操作系统和Shell的命令。绝不能混合使用不同平台的命令。
Phase 2: Plan (discover repos and generate environment-specific steps)
阶段2:制定计划(发现仓库并生成适配环境的步骤)
Step 1: Discover Repositories
步骤1:发现仓库
Use the appropriate command for the detected environment. NOTE: directories are hidden — commands must handle hidden files/directories.
.gitFor PowerShell (Windows):
powershell
Get-ChildItem -Path <target> -Recurse -Directory -Hidden -Filter ".git" -Depth <N> -ErrorAction SilentlyContinue | ForEach-Object { $_.Parent.FullName }⚠️ CRITICAL: The flag (or ) is REQUIRED because is a hidden directory on Windows. Without it, most or all repositories will be missed.
-Hidden-Force.gitFor bash/zsh (macOS/Linux):
bash
find <target> -maxdepth <N> -type d -name ".git" 2>/dev/null | sed 's/\/.git$//'For Git Bash on Windows:
bash
find <target> -maxdepth <N> -type d -name ".git" 2>/dev/null | sed 's/\/.git$//'Default target: current working directory. Default depth: 3 levels.
Display: "Found X git repositories." followed by the list.
使用适配检测到的环境的命令。注意: 目录是隐藏的——命令必须能处理隐藏文件/目录。
.gitWindows PowerShell:
powershell
Get-ChildItem -Path <target> -Recurse -Directory -Hidden -Filter ".git" -Depth <N> -ErrorAction SilentlyContinue | ForEach-Object { $_.Parent.FullName }⚠️ 关键提示:必须使用 标志(或 ),因为Windows上的是隐藏目录。如果不使用该标志,大部分或全部仓库会被遗漏。
-Hidden-Force.gitmacOS/Linux bash/zsh:
bash
find <target> -maxdepth <N> -type d -name ".git" 2>/dev/null | sed 's/\/.git$//'Windows Git Bash:
bash
find <target> -maxdepth <N> -type d -name ".git" 2>/dev/null | sed 's/\/.git$//'默认目标:当前工作目录。默认深度:3层。
显示内容:“找到X个Git仓库。” 并附上仓库列表。
Step 2: Generate Parallel Execution Plan
步骤2:生成并行执行计划
Based on the detected agent identity, plan the parallel strategy:
| Agent | Parallel Strategy |
|---|---|
| GitHub Copilot CLI | Use multiple parallel tool calls (powershell tool) to run |
| Claude Code | Use Agent Teams / TodoWrite+TodoRead pattern to dispatch sub-agents, one per batch of repos. |
| Other agents | Use whatever parallel/concurrent execution mechanism is available. |
Display the plan before executing, e.g.:
Plan: Sync 12 repositories in parallel
Strategy: 12 parallel tool calls (GitHub Copilot CLI)
Command per repo: git -C <path> pull --ff-only根据检测到的Agent身份,制定并行策略:
| Agent | 并行策略 |
|---|---|
| GitHub Copilot CLI | 使用多个并行工具调用(powershell工具),同时为所有仓库执行 |
| Claude Code | 使用Agent Teams / TodoWrite+TodoRead模式调度子Agent,每个子Agent处理一批仓库。 |
| 其他Agent | 使用任何可用的并行/并发执行机制。 |
执行前显示计划,例如:
计划:并行同步12个仓库
策略:12个并行工具调用(GitHub Copilot CLI)
每个仓库执行的命令:git -C <path> pull --ff-onlyPhase 3: Execute (parallel sync)
阶段3:执行(并行同步)
SYNC ALL REPOS IN PARALLEL, NOT SEQUENTIALLY!
For each repository, run in parallel:
- Check if a remote is configured:
git -C <repo> remote - If no remote → classify as "Skipped"
- If remote exists → run
git -C <repo> pull --ff-only - Classify result:
- Output contains "Already up to date" → "Up to date"
- Pull succeeded with changes → "Synced"
- Pull failed → "Failed" (capture error message)
Never sync repos one by one. The whole point of this skill is parallelism.
必须并行同步所有仓库,禁止串行执行!
为每个仓库并行执行以下操作:
- 检查是否已配置远程仓库:
git -C <repo> remote - 如果没有远程仓库 → 标记为“已跳过”
- 如果存在远程仓库 → 执行
git -C <repo> pull --ff-only - 分类执行结果:
- 输出包含“Already up to date” → “已同步至最新”
- 拉取变更成功 → “已同步”
- 拉取失败 → “失败”(捕获错误信息)
禁止逐个同步仓库。本技能的核心就是并行执行。
Phase 4: Report & Recommendations
阶段4:报告与建议
Summary Report
汇总报告
=== Git Sync Summary ===
Total: N repositories
Synced: X
Up to date: Y
Skipped: Z (no remote)
Failed: W
Failed repositories:
- repo-name: error message=== Git 同步汇总 ===
总计: N个仓库
已同步: X个
已最新: Y个
已跳过: Z个(无远程仓库)
失败: W个
失败的仓库:
- 仓库名称: 错误信息Environment-Specific Recommendations
适配环境的建议
Provide recommendations ONLY for the detected environment:
- Windows PowerShell: If repos failed due to path length, suggest enabling long paths: . Suggest
git config --system core.longpaths truefor credential management.git config --global credential.helper manager - macOS/Linux bash: If repos failed due to permissions, suggest or SSH key setup. Suggest
chmod(macOS) orgit config --global credential.helper osxkeychain(Linux).git config --global credential.helper store - NEVER recommend commands from a different platform (e.g., do NOT suggest on Windows, do NOT suggest
chmodon Linux).credential.helper manager
仅针对检测到的环境提供建议:
- Windows PowerShell:如果仓库因路径长度问题同步失败,建议启用长路径:。建议使用
git config --system core.longpaths true进行凭据管理。git config --global credential.helper manager - macOS/Linux bash:如果仓库因权限问题同步失败,建议使用或设置SSH密钥。macOS用户建议使用
chmod,Linux用户建议使用git config --global credential.helper osxkeychain。git config --global credential.helper store - 绝不要推荐其他平台的命令(例如,不要在Windows上建议,不要在Linux上建议
chmod)。credential.helper manager