code-sync
4
总安装量
2
周安装量
#54032
全站排名
安装命令
npx skills add https://github.com/niracler/skill --skill code-sync
Agent 安装分布
amp
2
opencode
2
kimi-cli
2
codex
2
gemini-cli
2
Skill 文档
Code Sync
Batch sync all git repos under ~/code â push (end-of-day) or pull (start-of-day).
Prerequisites
| Tool | Type | Required | Install |
|---|---|---|---|
| git | cli | Yes | brew install git or git-scm.com |
| git-workflow | skill | No | Included 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 says | Mode |
|---|---|
| ãä¸ç忥ãor “push” | Push |
| ãä¸çæ´æ°ãor “pull” | Pull |
| ã忥代ç ããcode-syncã | Ask user |
Workflow (shared by both modes)
- 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 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:
## {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 |