niracler

code-sync

5
0
# Install this skill:
npx skills add niracler/skill --skill "code-sync"

Install specific skill from multi-skill repository

# 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」「下班同步」「上班更新」.

# SKILL.md


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).

Mode Selection

User says Mode
「下班同步」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 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:

Category Condition Action
up-to-date dirty_count == 0 && ahead == 0 Report
needs-push dirty_count == 0 && ahead > 0 Auto git push
dirty dirty_count > 0 Interactive
no-upstream has_upstream == false Ask user

Pull mode:

Category Condition Action
up-to-date dirty_count == 0 && behind == 0 Report
needs-pull dirty_count == 0 && behind > 0 Auto git pull --ff-only
dirty+behind dirty_count > 0 && behind > 0 Interactive
fetch-error fetch_error == true Report, skip

Exception Handling

Situation Steps
Dirty repo (push) git diff --stat + git status → describe to user → ask: commit, stash, or skip. If committed, 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:

## {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

Issue Fix
scan.sh finds 0 repos Check ~/code/*/ has git repos
fetch_error Check network, SSH keys
ff-only fails Rebase or merge manually
Push rejected Pull first, then push

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.