返回顶部
w

workspace-git-sync工作区Git同步

>

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
98
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

workspace-git-sync

Workspace Git Sync

将 OpenClaw 工作目录同步到 Git 仓库,实现自动备份和版本控制。

功能特性

  • - 自动排除:默认排除 skills/、pycache/、.clawhub/ 等
  • Git 操作:自动执行 pull → copy → commit → push
  • 冲突处理:同步前自动拉取远程变更
  • 安全推送:使用 --force-with-lease 而非 --force

使用方法

基础用法

bash

同步到指定 Git 仓库


python3 ~/.openclaw/workspace/skills/workspace-git-sync/scripts/sync_workspace.py ~/projects/backup-repo

带自定义提交信息

python3 ~/.openclaw/workspace/skills/workspace-git-sync/scripts/sync_workspace.py ~/projects/backup-repo 每日备份

Python API

python
from scripts.syncworkspace import syncworkspacetogit, quicksync, forcesync

标准同步

result = syncworkspaceto_git(~/projects/backup-repo)

快速同步

result = quick_sync(~/projects/backup-repo, 快速备份)

强制同步(危险)

result = force_sync(~/projects/backup-repo, 强制覆盖)

参数说明

参数类型默认值说明
targetrepopathstr必需目标 Git 仓库本地路径
branch
str | 自动检测 | 目标分支 | | commit_msg | str | 自动生成 | 提交信息 | | exclude_patterns | list | [skills, .git, ...] | 额外排除项 | | pullbeforepush | bool | True | 推送前是否先 pull | | strategy | str | rebase | 合并策略 (rebase/merge/force) |

执行流程

  1. 1. 检查源目录 — 验证 ~/.openclaw/workspace/ 存在
  2. 检查目标仓库 — 验证是有效的 Git 仓库
  3. 拉取远程变更 — git pull --rebase 避免冲突
  4. 清理目标目录 — 删除旧文件(保留 .git/)
  5. 复制文件 — 从 workspace 复制到目标目录
  6. 提交并推送 — git add -A → git commit → git push

默认排除项

以下文件/目录会自动排除,不会同步:

  • - skills/ — 技能目录(通常很大)
  • .git/ — Git 元数据
  • pycache/ — Python 缓存
  • .DSStore — macOS 系统文件
  • nodemodules/ — Node.js 依赖
  • .clawhub/ — OpenClaw 缓存

使用示例

示例 1:基础同步

用户:将 workspace 同步到 ~/backup/openclaw
AI:执行 sync_workspace.py ~/backup/openclaw

示例 2:指定分支和提交信息

python
syncworkspaceto_git(
targetrepopath=~/github-pages,
branch=gh-pages,
commit_msg=Deploy workspace backup
)

示例 3:强制同步(危险)

python

跳过 pull,直接强制推送


force_sync(~/projects/backup-repo, Emergency update)

错误处理

错误场景处理方式
源目录不存在报错,检查 ~/.openclaw/workspace/
目标不是 Git 仓库
报错,提示初始化仓库:git init | | 合并冲突 | 中止操作,提示手动解决 | | 无推送权限 | 显示 Git 错误,检查权限或 Token |

脚本位置

~/.openclaw/workspace/skills/workspace-git-sync/
├── SKILL.md
└── scripts/
└── sync_workspace.py

注意事项

  1. 1. 目标必须是 Git 仓库:文件夹必须包含 .git/ 目录
  2. 路径格式:支持 ~ 展开(如 ~/projects/repo)
  3. 数据安全:清理目标目录时会保留 .git/,不会丢失版本历史
  4. 权限要求:对目标目录有读写权限,对 Git 仓库有写权限

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 workspace-git-sync-1775976130 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 workspace-git-sync-1775976130 技能

通过命令行安装

skillhub install workspace-git-sync-1775976130

下载

⬇ 下载 workspace-git-sync v1.0.0(免费)

文件大小: 7.44 KB | 发布时间: 2026-4-13 12:36

v1.0.0 最新 2026-4-13 12:36
Initial release: Sync your OpenClaw workspace to a local Git repository with automated backup and version control.

- Adds commands to sync `~/.openclaw/workspace/` to any specified Git repo, including pull → copy → commit → push.
- Supports exclusion of large/system/generated folders (e.g., `skills/`, `.git/`, `__pycache__/`).
- Handles merge conflicts and uses safe push strategies.
- Provides Python API and CLI usage examples.
- Includes error handling for common issues like missing directories or permissions.

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部