AgentSkillsCN

code-sync

当您需要在不同设备间同步~/code下的所有Git仓库时使用,通常在每日下班时(push)或每日上班时(pull)触发。触发关键词包括:“同步代码”、“code-sync”、“下班同步”、“上班更新”。

SKILL.md
--- frontmatter
name: code-sync
description: Use when syncing all git repos under ~/code across machines, typically at end-of-day (push) or start-of-day (pull). Triggers on「同步代码」「code-sync」「下班同步」「上班更新」.

Code Sync

Batch sync all git repos under ~/code — push (end-of-day) or pull (start-of-day).

Prerequisites

ToolTypeRequiredInstall
gitcliYesbrew install git or git-scm.com
git-workflowskillNoIncluded in npx skills add niracler/skill (used for dirty repo commits)

Do NOT proactively verify these tools on skill load. If a command fails due to a missing tool, directly guide the user through installation and configuration step by step.

Mode Selection

User saysMode
「下班同步」or "push"Push
「上班更新」or "pull"Pull
「同步代码」「code-sync」Ask user

Workflow (shared by both modes)

  1. Scan → 2. Categorize → 3. Batch action (auto, no confirmation) → 4. Handle exceptions (interactive) → 5. Summary

If all repos are up-to-date, report that and stop.

Scan

bash
bash scripts/scan.sh           # Push: local data only
bash scripts/scan.sh --fetch   # Pull: fetch remote first (10s timeout/repo)

Output: JSON array with fields path, name, branch, remote, remote_url, dirty_count, has_upstream, ahead, behind, and fetch_error (only on --fetch failure).

Categorize

Push mode:

CategoryConditionAction
up-to-datedirty_count == 0 && ahead == 0Report
needs-pushdirty_count == 0 && ahead > 0Auto git push
dirtydirty_count > 0Interactive
no-upstreamhas_upstream == falseAsk user

Pull mode:

CategoryConditionAction
up-to-datedirty_count == 0 && behind == 0Report
needs-pulldirty_count == 0 && behind > 0Auto git pull --ff-only
dirty+behinddirty_count > 0 && behind > 0Interactive
fetch-errorfetch_error == trueReport, skip

Exception Handling

SituationSteps
Dirty repo (push)git diff --stat + git status → describe to user → ask: commit, stash, or skip. If commit, use git-workflow skill to commit and push.
No upstream (push)Report → ask: set upstream and push (git push -u origin <branch>), or skip
ff-only fails (pull)git log --oneline HEAD..@{u} + @{u}..HEAD → explain divergence → suggest: rebase, merge, or skip
Dirty + behind (pull)Report both issues → ask: stash and pull (stash, pull --ff-only, pop), or skip

Summary

Group repos by outcome after all operations complete:

text
## {Push|Pull} Summary

{Pushed|Updated} (N):
  - repo-name (branch, N commits)
Already up-to-date (N):
  - repo-a, repo-b, ...
Resolved (N):
  - repo-c: action taken
Skipped (N):
  - repo-d: reason

Common Issues

IssueFix
scan.sh finds 0 reposCheck ~/code/*/ has git repos
fetch_errorCheck network, SSH keys
ff-only failsRebase or merge manually
Push rejectedPull first, then push