sync

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Sync Skill

同步Skill

Quick git synchronization with remote repository.
与远程仓库快速进行Git同步。

Usage

使用方法

Commands

命令

bash
/sync              # Pull from origin main
/sync develop      # Pull from origin develop
/sync upstream     # Pull from upstream main (forks)
bash
/sync              # 从origin main拉取
/sync develop      # 从origin develop拉取
/sync upstream     # 从upstream main拉取(适用于复刻仓库)

Korean Triggers

韩文触发词

  • "동기화"
  • "원격에서 가져와"
  • "풀 받아"
  • "동기화"(同步)
  • "원격에서 가져와"(从远程获取)
  • "풀 받아"(拉取)

Workflow

工作流程

1. Pre-sync Check

1. 同步前检查

bash
git status
If working directory has uncommitted changes:
Options:
  1. Stash:
    git stash
    → sync →
    git stash pop
  2. Commit first: Suggest using
    /cp
  3. Discard: Only if user confirms with
    git checkout .
bash
git status
如果工作区存在未提交的变更:
选项:
  1. 暂存
    git stash
    → 同步 →
    git stash pop
  2. 先提交:建议使用
    /cp
    命令
  3. 丢弃:仅当用户确认后执行
    git checkout .

2. Fetch and Pull

2. 获取并拉取

Default (origin main):
bash
git pull origin main
With rebase (cleaner history):
bash
git pull --rebase origin main
默认操作(origin main):
bash
git pull origin main
使用变基(更整洁的提交历史):
bash
git pull --rebase origin main

3. Report Results

3. 结果报告

After successful sync:
Synced with origin/main
- 3 commits pulled
- Files changed: 5
- No conflicts
同步成功后:
已与origin/main同步
- 拉取了3次提交
- 变更文件数:5
- 无冲突

Handling Conflicts

冲突处理

If merge conflicts occur:
  1. List conflicting files
  2. Offer to help resolve
  3. After resolution:
    git add <files>
    git commit
如果出现合并冲突:
  1. 列出冲突文件
  2. 提供冲突解决协助
  3. 解决后执行:
    git add <files>
    git commit

Common Scenarios

常见场景

Fork Workflow

复刻仓库工作流程

bash
undefined
bash
undefined

Add upstream if not exists

如果不存在则添加upstream远程仓库

git remote add upstream <original-repo-url>
git remote add upstream <original-repo-url>

Sync with upstream

与upstream同步

git fetch upstream git merge upstream/main
undefined
git fetch upstream git merge upstream/main
undefined

Diverged Branches

分支分歧处理

If local and remote have diverged:
bash
undefined
如果本地与远程分支出现分歧:
bash
undefined

Option 1: Merge (default)

选项1:合并(默认)

git pull origin main
git pull origin main

Option 2: Rebase (cleaner)

选项2:变基(更整洁)

git pull --rebase origin main
git pull --rebase origin main

Option 3: Reset (destructive, ask user)

选项3:重置(破坏性操作,需询问用户)

git fetch origin git reset --hard origin/main
undefined
git fetch origin git reset --hard origin/main
undefined

Error Handling

错误处理

ErrorSolution
"Uncommitted changes"Stash or commit first
"Merge conflict"Help resolve conflicts
"Remote not found"Check
git remote -v
错误解决方案
"未提交的变更"暂存或先提交
"合并冲突"协助解决冲突
"未找到远程仓库"检查
git remote -v