git-sync-all

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git 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:
  1. Operating System: Run a command to detect the OS.
    • Windows:
      [System.Environment]::OSVersion
      or
      $env:OS
    • macOS/Linux:
      uname -s
  2. Shell environment: Identify the current shell.
    • PowerShell:
      $PSVersionTable.PSVersion
    • bash/zsh:
      echo $SHELL
      and
      echo $BASH_VERSION
      or
      echo $ZSH_VERSION
  3. Agent identity: Identify which agent is running this skill (Claude Code, GitHub Copilot CLI, Cursor, etc.) based on the agent's own context/identity.
  4. Git availability: Run
    git --version
    to verify git is installed.
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.1
All subsequent phases MUST use ONLY commands appropriate for the detected OS and shell. Never mix platform commands.

在执行任何操作前,检测并明确显示以下信息:
  1. 操作系统:运行命令检测操作系统。
    • Windows:
      [System.Environment]::OSVersion
      $env:OS
    • macOS/Linux:
      uname -s
  2. Shell环境:识别当前使用的Shell。
    • PowerShell:
      $PSVersionTable.PSVersion
    • bash/zsh:
      echo $SHELL
      echo $BASH_VERSION
      echo $ZSH_VERSION
  3. Agent身份:根据Agent自身的上下文/身份,识别运行该技能的Agent(如Claude Code、GitHub Copilot CLI、Cursor等)。
  4. Git可用性:运行
    git --version
    验证Git是否已安装。
清晰显示检测结果,例如:
环境检测结果:
  操作系统:    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:
.git
directories are hidden — commands must handle hidden files/directories.
For PowerShell (Windows):
powershell
Get-ChildItem -Path <target> -Recurse -Directory -Hidden -Filter ".git" -Depth <N> -ErrorAction SilentlyContinue | ForEach-Object { $_.Parent.FullName }
⚠️ CRITICAL: The
-Hidden
flag (or
-Force
) is REQUIRED because
.git
is a hidden directory on Windows. Without it, most or all repositories will be missed.
For 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.
使用适配检测到的环境的命令。注意:
.git
目录是隐藏的——命令必须能处理隐藏文件/目录。
Windows PowerShell:
powershell
Get-ChildItem -Path <target> -Recurse -Directory -Hidden -Filter ".git" -Depth <N> -ErrorAction SilentlyContinue | ForEach-Object { $_.Parent.FullName }
⚠️ 关键提示:必须使用
-Hidden
标志(或
-Force
),因为Windows上的
.git
是隐藏目录。如果不使用该标志,大部分或全部仓库会被遗漏。
macOS/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:
AgentParallel Strategy
GitHub Copilot CLIUse multiple parallel tool calls (powershell tool) to run
git pull
for all repos simultaneously. For large batches (20+), use sub-agents via the
task
tool.
Claude CodeUse Agent Teams / TodoWrite+TodoRead pattern to dispatch sub-agents, one per batch of repos.
Other agentsUse 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工具),同时为所有仓库执行
git pull
。对于大型批量(20个以上),通过
task
工具使用子Agent。
Claude Code使用Agent Teams / TodoWrite+TodoRead模式调度子Agent,每个子Agent处理一批仓库。
其他Agent使用任何可用的并行/并发执行机制。
执行前显示计划,例如:
计划:并行同步12个仓库
  策略:12个并行工具调用(GitHub Copilot CLI)
  每个仓库执行的命令:git -C <path> pull --ff-only

Phase 3: Execute (parallel sync)

阶段3:执行(并行同步)

SYNC ALL REPOS IN PARALLEL, NOT SEQUENTIALLY!
For each repository, run in parallel:
  1. Check if a remote is configured:
    git -C <repo> remote
  2. If no remote → classify as "Skipped"
  3. If remote exists → run
    git -C <repo> pull --ff-only
  4. 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.

必须并行同步所有仓库,禁止串行执行!
为每个仓库并行执行以下操作:
  1. 检查是否已配置远程仓库:
    git -C <repo> remote
  2. 如果没有远程仓库 → 标记为“已跳过”
  3. 如果存在远程仓库 → 执行
    git -C <repo> pull --ff-only
  4. 分类执行结果:
    • 输出包含“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:
    git config --system core.longpaths true
    . Suggest
    git config --global credential.helper manager
    for credential management.
  • macOS/Linux bash: If repos failed due to permissions, suggest
    chmod
    or SSH key setup. Suggest
    git config --global credential.helper osxkeychain
    (macOS) or
    git config --global credential.helper store
    (Linux).
  • NEVER recommend commands from a different platform (e.g., do NOT suggest
    chmod
    on Windows, do NOT suggest
    credential.helper manager
    on Linux).
仅针对检测到的环境提供建议
  • Windows PowerShell:如果仓库因路径长度问题同步失败,建议启用长路径:
    git config --system core.longpaths true
    。建议使用
    git config --global credential.helper manager
    进行凭据管理。
  • macOS/Linux bash:如果仓库因权限问题同步失败,建议使用
    chmod
    或设置SSH密钥。macOS用户建议使用
    git config --global credential.helper osxkeychain
    ,Linux用户建议使用
    git config --global credential.helper store
  • 绝不要推荐其他平台的命令(例如,不要在Windows上建议
    chmod
    ,不要在Linux上建议
    credential.helper manager
    )。