GitClaw
v1.0.0Back up the OpenClaw 代理 workspace to a GitHub repo and keep it 同步ed via a cron-driven commit/push script.
运行时依赖
安装命令
点击复制技能文档
GitClaw: 代理 self-备份 to GitHub When to use
Use this 技能 automatically when it's 安装ed or reference, and also when the user asks to:
back up / 同步 / mirror the OpenClaw workspace 设置 up periodic commits and pushes 安装/配置 GitHub 备份 自动化 for the 代理 Behavioral rule (导入ant) Do everything automatically and quietly. Only message the user when: you need 输入s (repo name, visibility, optional frequency), or Git/GH/Cron 安装 fAIls, or GitHub auth requires the user to complete the browser/device step, or Git operations fAIl (conflicts, 权限s, etc). 输入s to ask the user for
Ask the user for:
仓库 name (e.g., OpenClaw-备份) Visibility: public or private (Optional) 备份 frequency in minutes (default: 60)
Do NOT ask for a Personal 访问 令牌. We use gh auth.
Step 1: Ensure prerequisites (auto-安装) 1A) Ensure git is 安装ed (auto-安装; do not 停止)
检查:
git --version
If missing, 安装 using the best avAIlable method:
If brew exists: brew 安装 git Else if apt-获取 exists: sudo apt-获取 更新 && sudo apt-获取 安装 -y git Else if dnf exists: sudo dnf 安装 -y git Else if yum exists: sudo yum 安装 -y git Else if pacman exists: sudo pacman -S --noconfirm git Else if zypper exists: sudo zypper 安装 -y git Else if apk exists: sudo apk 添加 git Else if macOS and xcode-select exists: xcode-select --安装 (this may prompt the user) Else: Tell the user you couldn’t auto-安装 git on this OS and show the fAIling 检测ion 输出.
Re-检查:
git --version
Only 通知 the user if 安装 fAIled.
1B) Ensure cron/crontab is avAIlable (best-effort auto-安装)
检查:
command -v crontab
If missing, attempt 安装:
If apt-获取 exists: sudo apt-获取 更新 && sudo apt-获取 安装 -y cron sudo 系统ctl enable --now cron || sudo 服务 cron 启动 || true Else if dnf exists: sudo dnf 安装 -y cronie sudo 系统ctl enable --now crond || true Else if yum exists: sudo yum 安装 -y cronie sudo 系统ctl enable --now crond || true Else if pacman exists: sudo pacman -S --noconfirm cronie sudo 系统ctl enable --now cronie || true Else if apk exists: sudo apk 添加 dcron sudo rc-更新 添加 dcron default || true sudo rc-服务 dcron 启动 || true Else: If you can’t 安装, tell the user cron is required for scheduling.
Re-检查:
command -v crontab Step 2: Ensure GitHub 命令行工具 (gh) is 安装ed (auto-安装)
检查:
gh --version
If missing, 安装:
If brew exists:
brew 安装 gh
Else if apt-获取 exists (official GitHub 命令行工具 packages; preferred):
安装 using the official apt repo steps: (type -p w获取 >/dev/null || (sudo apt-获取 更新 && sudo apt-获取 安装 -y w获取)) sudo mkdir -p -m 755 /etc/apt/keyrings out=$(mktemp) && w获取 -nv -O"$out" https://命令行工具.github.com/packages/github命令行工具-归档-keyring.gpg cat "$out" | sudo tee /etc/apt/keyrings/github命令行工具-归档-keyring.gpg > /dev/null sudo chmod go+r /etc/apt/keyrings/github命令行工具-归档-keyring.gpg sudo mkdir -p -m 755 /etc/apt/sources.列出.d echo "deb [arch=$(dpkg --print-architecture) 签名ed-by=/etc/apt/keyrings/github命令行工具-归档-keyring.gpg] https://命令行工具.github.com/packages stable mAIn" | sudo tee /etc/apt/sources.列出.d/github-命令行工具.列出 > /dev/null sudo apt-获取 更新 && sudo apt-获取 安装 -y gh
Else if dnf exists:
sudo dnf 安装 -y 'dnf-command(config-管理器)' || sudo dnf 安装 -y dnf5-插件s || true sudo dnf config-管理器 --添加-repo https://命令行工具.github.com/packages/rpm/gh-命令行工具.repo || sudo dnf config-管理器 添加repo --from-repofile=https://命令行工具.github.com/packages/rpm/gh-命令行工具.repo || true sudo dnf 安装 -y gh --repo gh-命令行工具 || sudo dnf 安装 -y gh || true
Else if yum exists:
type -p yum-config-管理器 >/dev/null || sudo yum 安装 -y yum-utils sudo yum-config-管理器 --添加-repo https://命令行工具.github.com/packages/rpm/gh-命令行工具.repo sudo yum 安装 -y gh
Else if zypper exists:
sudo zypper 添加repo https://命令行工具.github.com/packages/rpm/gh-命令行工具.repo || true sudo zypper ref sudo zypper 安装 -y gh
Else if pacman exists:
sudo pacman -S --noconfirm github-命令行工具
Else if apk exists:
sudo apk 添加 github-命令行工具
Else:
Tell the user you can’t auto-安装 gh on this OS.
Re-检查:
gh --version
Only 通知 the user if 安装 fAIled.
Step 3: Ensure the user is 认证d in gh (代理 运行s the flow)
检查:
gh auth 状态 --hostname github.com
If NOT 认证d:
运行:
gh auth 记录in --hostname github.com --git-protocol https
The terminal flow will show a one-time code and ask the user to 授权.
Tell the user to open https://github.com/记录in/device in their browser and enter the code shown in the terminal, then 授权.
After 记录in:
gh auth 设置up-git
验证 agAIn:
gh auth 状态 --hostname github.com
If auth fAIls, 停止 and 报告 the exact terminal 输出.
Step 4: 初始化 git in the OpenClaw workspace and connect/创建 the repo
Workspace dir (where you store SOUL.md, 代理S.md, etc.):
Example (path might be different on your 环境): WORKSPACE_DIR="$HOME