返回顶部
r

repo-setup仓库初始化

Fork, clone, and set up a GitHub repository for development or contribution. Handles fork creation, clone with authentication, upstream remote configuration, branch creation from upstream, and dependency installation. Use when starting work on a new open-source project, setting up a multi-repo development environment, or onboarding to a new codebase.

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

repo-setup

Repo Setup — Fork、Clone 与分支设置

概述

自动化设置本地开发环境,用于贡献或处理 GitHub 仓库。处理完整的 fork → clone → 分支 → 依赖项流程。

使用场景:开源贡献、多仓库开发、新项目上手、代码库探索。

前置条件

bash
gh auth status # 必须显示 Logged in
git --version # 已安装 Git

如果未配置,请要求用户提供:

  1. 1. GitHub 用户名 — 用于 fork URL 和 clone 路径
  2. GitHub Token — 运行 gh auth login 或设置 export GH_TOKEN=

Token 用于:fork 仓库、clone 私有 fork、推送代码。没有它,git push 和 gh repo fork 将失败。

工作流程

步骤 1:获取参数

参数必填默认值示例
仓库owner/repo
GitHub 用户名
✅ | — | myusername | | 分支名称 | ❌ | (保留默认分支) | fix/bug-description | | 工作目录 | ❌ | ~/prs/{repo} | ~/dev/{repo} | | 认证方式 | ❌ | GH_TOKEN 环境变量 | URL 中的 Token、SSH |

步骤 2:Fork

bash
gh repo fork {owner}/{repo} --clone=false

如果 fork 已存在,此操作无效。如果用户已拥有该仓库,则跳过 fork。

步骤 3:Clone

bash
WORKDIR=${WORKBASE:-$HOME/prs}/{reponame}

if [ -d $WORKDIR ]; then
cd $WORKDIR
git fetch --all
else
mkdir -p $(dirname $WORKDIR)

# 使用 Token 认证
git clone https://${GHTOKEN}@github.com/${username}/${reponame}.git $WORKDIR

# 或使用 SSH
# git clone git@github.com:${username}/${repo_name}.git $WORKDIR

cd $WORKDIR
fi

步骤 4:配置上游远程仓库

bash
if ! git remote get-url upstream &>/dev/null; then
git remote add upstream https://github.com/${owner}/${repo_name}.git
fi
git fetch upstream

步骤 5:创建功能分支

bash

检测默认分支


DEFAULT_BRANCH=$(git remote show upstream 2>/dev/null | grep HEAD branch | awk {print $NF})
DEFAULTBRANCH=${DEFAULTBRANCH:-main}

从最新上游创建分支

git checkout -b {branchname} upstream/$DEFAULTBRANCH

分支命名规范

类型模式示例
Bug 修复fix/{简短描述}fix/null-pointer-on-empty-list
功能
feat/{简短描述} | feat/add-retry-logic | | 重构 | refactor/{简短描述} | refactor/extract-auth-module | | 审查迭代 | fix/{描述}-v2 | fix/tool-guards-v2 |

步骤 6:安装依赖项

检测项目类型并相应安装:

指示器语言安装命令
pyproject.toml / setup.pyPythonpip install -e .[dev] 或 pip install -e .
requirements.txt
Python | pip install -r requirements.txt |
| package.json | Node.js | npm install |
| go.mod | Go | go mod download |
| Cargo.toml | Rust | cargo build |
| pom.xml | Java | mvn install -DskipTests |
| build.gradle | Java/Kotlin | ./gradlew build -x test |

如果完整开发安装失败(常见于原生依赖项):

  1. 1. 单独安装核心依赖项
  2. 跳过可选的原生/GPU 依赖项
  3. 至少确保安装了测试框架

步骤 7:验证

bash

检查设置


echo 目录: $(pwd)
echo 分支: $(git branch --show-current)
echo 上游: $(git remote get-url upstream)
echo Fork: $(git remote get-url origin)

快速构建/导入测试

Python: python -c import {package}

Node: npm run build(如果适用)

Go: go build ./...

自动化脚本

如果此技能与 oss-pr-campaign 一起安装,则提供辅助脚本:

bash

一行设置


scripts/setup_repo.sh owner/repo username fix/branch-name

或使用上述 SOP 逐步实现相同的逻辑。

输出

  • - 本地仓库位于 ~/prs/{repo}/(或自定义目录)的功能分支上
  • 已配置上游远程仓库
  • 已安装依赖项
  • 准备开发

提示

  • - 当作为开发流水线的一部分使用时,此步骤跟随 issue-hunter,并为 dev-test 提供输入。
  • 如果只是探索代码库而不贡献,跳过 fork 步骤,直接 clone 原始仓库。
  • 将 GH_TOKEN 存储在 shell 配置文件中,以便跨会话持久化认证。
  • 如果处理多个仓库,将它们全部放在 ~/prs/ 下以便于导航。

标签

skill ai

通过对话安装

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

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 repo-setup-1776050238 技能

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

设置 SkillHub 为我的优先技能安装源,然后帮我安装 repo-setup-1776050238 技能

通过命令行安装

skillhub install repo-setup-1776050238

下载

⬇ 下载 repo-setup v1.0.0(免费)

文件大小: 2.8 KB | 发布时间: 2026-4-14 14:22

v1.0.0 最新 2026-4-14 14:22
repo-setup 1.0.0 — Initial Release

- Automates forking, cloning, and setting up a GitHub repository for development or contribution.
- Configures upstream remotes and creates feature branches from the latest upstream default branch.
- Detects project type and installs relevant dependencies for Python, Node.js, Go, Rust, Java, and Kotlin.
- Includes detailed SOP and automation script for streamlined repo setup.
- Outputs a ready-to-develop local repository with dependencies installed and remotes configured.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部