Git Manager Skill
This skill safely executes common Git commands. It wraps git CLI with additional safety checks and structured output.
Capabilities
- -
status - Show working tree status - INLINECODE2 - Stage changes and commit (with message)
- INLINECODE3 - Push to remote
- INLINECODE4 - Pull from remote (rebase or merge)
- INLINECODE5 - Create, list, delete branches
- INLINECODE6 - Switch branches
- INLINECODE7 - Merge branches
- INLINECODE8 - Stash/apply changes
- INLINECODE9 - Show commit history
- INLINECODE10 - Show changes
Safety Features
- - No force push by default (
--force must be explicit) - Protected branches: Cannot delete or commit directly to
main/master/ INLINECODE14 - Dry-run mode: Preview operations before execution
- Auto-commit message quality check (LLM can improve messages)
- All operations logged to INLINECODE15
When to Use
User says:
- - "查看Git状态"
- "提交代码"
- "推送到远程仓库"
- "拉取最新代码"
- "创建新分支"
- "合并分支"
- "查看提交历史"
Invocation
CODEBLOCK0
Output Format
JSON with fields:
- -
success: boolean - INLINECODE17 : string (raw git output)
- INLINECODE18 : string (if failed)
- INLINECODE19 : array (for commit)
- INLINECODE20 : string (after commit)
- INLINECODE21 : current branch
Example:
CODEBLOCK1
Configuration via Environment
- -
GIT_MANAGER_LOG: path to activity log (default ~/.openclaw/logs/git-manager.log) - INLINECODE24 : set "1" to default to dry-run
- INLINECODE25 : comma-separated list (default
main,master,production)
Integration with OpenClaw
When used from a developer role session:
- - Automatically respects the session's
cwd as the repo if --repo not provided - Can chain operations:
status -> commit -> push in one go - Suggest commit messages based on
git diff (if --message omitted)
Examples in OpenClaw Sessions
CODEBLOCK2
Limitations
- - Does not handle merge conflicts automatically (requires human)
- No rebase interactive (complex history edits)
- Assumes standard Git flow (no custom hooks)
- SSH keys must be pre-configured for push/pull
Troubleshooting
| Issue | Check |
|---|
| Permission denied (publickey) | SSH agent running? INLINECODE34 |
| Not a git repository |
--repo path correct? |
| Branch protected | Cannot commit to main; create feature branch first |
| Merge conflict | Resolve manually; skill only detects conflict |
Future Enhancements
- - PR creation via GitHub CLI (
gh pr create) - Auto-version bump based on commit messages (semantic-release)
- Branch cleanup (delete merged branches)
Git Manager 技能
该技能安全地执行常见的Git命令。它在git命令行工具的基础上增加了额外的安全检查并输出结构化结果。
功能
- - status - 显示工作树状态
- commit - 暂存更改并提交(附带提交信息)
- push - 推送到远程仓库
- pull - 从远程仓库拉取(变基或合并)
- branch - 创建、列出、删除分支
- checkout - 切换分支
- merge - 合并分支
- stash - 暂存/应用更改
- log - 显示提交历史
- diff - 显示更改内容
安全特性
- - 默认禁止强制推送(必须显式使用--force参数)
- 受保护分支:无法直接删除或提交到main/master/production分支
- 预演模式:在执行前预览操作结果
- 自动提交信息质量检查(LLM可优化提交信息)
- 所有操作均记录日志至~/.openclaw/logs/git-manager.log
使用场景
用户说:
- - 查看Git状态
- 提交代码
- 推送到远程仓库
- 拉取最新代码
- 创建新分支
- 合并分支
- 查看提交历史
调用方式
bash
查看状态
git-manager --action status --repo /path/to/repo
提交所有更改
git-manager --action commit --repo /path/to/repo --message feat: add user auth
提交指定文件
git-manager --action commit --repo /path/to/repo --files [file1,file2] --message fix: bug in payment
推送
git-manager --action push --repo /path/to/repo --branch feature-xyz
拉取
git-manager --action pull --repo /path/to/repo --branch main
创建分支
git-manager --action branch --repo /path/to/repo --create new-branch --from main
切换分支
git-manager --action checkout --repo /path/to/repo --branch feature-xyz
查看差异
git-manager --action diff --repo /path/to/repo --files [file1]
输出格式
JSON格式,包含以下字段:
- - success: 布尔值
- output: 字符串(原始git输出)
- error: 字符串(如果失败)
- changedfiles: 数组(提交时)
- commitsha: 字符串(提交后)
- branch: 当前分支
示例:
json
{
success: true,
action: commit,
commit_sha: abc123def,
changedfiles: [src/auth.py, tests/testauth.py],
output: [main abc123] feat: add user auth\n 2 files changed, 45 insertions(+)
}
环境变量配置
- - GITMANAGERLOG: 活动日志路径(默认~/.openclaw/logs/git-manager.log)
- GITMANAGERDRYRUN: 设置为1默认启用预演模式
- GITMANAGERPROTECTEDBRANCHES: 逗号分隔列表(默认main,master,production)
与OpenClaw的集成
在开发者角色会话中使用时:
- - 如果未提供--repo参数,自动将会话的cwd作为仓库路径
- 可链式操作:status -> commit -> push一气呵成
- 根据git diff建议提交信息(如果省略--message参数)
OpenClaw会话示例
python
开发者会话
sessions_spawn(
task=提交刚才修改的登录页面样式,
config=configs/developer.yaml,
attachments=[]
)
该技能将执行:git add . && git commit -m style: improve login page && git push
局限性
- - 无法自动处理合并冲突(需要人工介入)
- 不支持交互式变基(复杂历史编辑)
- 假设使用标准Git工作流(无自定义钩子)
- 推送/拉取需要预先配置SSH密钥
故障排除
| 问题 | 检查项 |
|---|
| 权限被拒绝(公钥) | SSH代理是否运行?ssh-add -l |
| 不是Git仓库 |
--repo路径是否正确? |
| 分支受保护 | 无法提交到main分支;先创建功能分支 |
| 合并冲突 | 手动解决;技能仅检测冲突 |
未来增强
- - 通过GitHub CLI创建PR(gh pr create)
- 基于提交信息自动版本升级(语义化发布)
- 分支清理(删除已合并的分支)