Skill: Remote
远程仓库管理技能 - 智能推送、拉取和多仓库同步。
核心功能
- 🚀 智能推送 - 安全检查、分批推送、防强制推送保护
- 📥 智能拉取 - 冲突预防、自动合并策略选择
- 🔗 多仓库管理 - 一键同步多个远程仓库
- 🌐 分支同步 - 自动同步远程分支状态
- 📊 状态监控 - 实时同步状态和差异报告
快速使用
# 安全推送
/remote push main --safe
# 智能拉取
/remote pull --auto
# 同步所有分支
/remote sync --all
# 多仓库推送
/remote push-all --remotes origin,backup
推送策略
安全推送流程
- 预检查 - 确认工作区干净
- 差异分析 - 显示即将推送的提交
- 冲突检测 - 检查远程是否有新提交
- 执行推送 - 确认后执行
git push - 状态确认 - 验证推送成功
推送选项
| 选项 | 说明 | 使用场景 |
|------|------|---------|
| --safe | 安全部全检查后推送 | 默认推荐 |
| --force-with-lease | 安全强制推送 | 确认需要覆盖时 |
| --no-verify | 跳过钩子(谨慎) | 紧急修复 |
| --tags | 同时推送标签 | 版本发布 |
危险操作警告
# ❌ 危险:可能覆盖他人提交
git push --force
# ✅ 安全:仅在远程无更新时强制
git push --force-with-lease
拉取策略
拉取方式对比
| 命令 | 说明 | 适用场景 |
|------|------|---------|
| git pull | 拉取并合并 | 快速同步 |
| git pull --rebase | 拉取并变基 | 保持线性历史 |
| git fetch | 仅拉取不合并 | 先查看再决定 |
智能拉取流程
- 获取远程更新 -
git fetch origin - 分析差异 - 比较本地与远程
- 冲突预判 - 检测潜在冲突
- 选择策略 - merge 或 rebase
- 执行拉取 - 合并/变基到本地
冲突处理
# 优先使用 rebase 保持历史整洁
git pull --rebase origin main
# 如果有冲突,解决后继续
git add <resolved-files>
git rebase --continue
# 放弃 rebase
git rebase --abort
多仓库同步
配置多远程
# 添加备用远程
git remote add backup https://github.com/org/backup.git
# 查看所有远程
git remote -v
同步命令
# 推送到所有远程
git push --all origin backup
# 同步特定分支
git push origin main && git push backup main
# 使用 sync 命令一键同步
/remote sync --all --remotes origin,backup,upstream
状态监控
检查远程状态
# 查看远程分支
git branch -r
# 查看本地与远程差异
git log HEAD..origin/main --oneline
# 查看远程提交
git log origin/main --oneline -5
配置
{
"remote": {
"safetyChecks": true,
"autoSync": false,
"multiRemote": true,
"defaultPushStrategy": "safe",
"remotes": {
"origin": "https://github.com/org/repo.git",
"backup": "https://github.com/org/backup.git"
}
}
}
最佳实践
✅ 推荐做法
- 推送前先拉取最新代码
- 使用
--force-with-lease替代--force - 定期同步远程分支状态
- 配置多远程备份
❌ 避免做法
- 直接使用
--force强制推送 - 长时间不同步远程更新
- 在 main 分支上强制推送
- 忽略远程冲突警告