Repo Setup — Fork, Clone & Branch Setup
Overview
Automate the setup of a local development environment for contributing to or working on GitHub repositories. Handles the full fork → clone → branch → dependencies pipeline.
Use cases: Open-source contribution, multi-repo development, new project onboarding, codebase exploration.
Prerequisites
CODEBLOCK0
If not configured, ask the user to provide:
- 1. GitHub username — used for fork URLs and clone paths
- GitHub token — run
gh auth login or set INLINECODE1
Token is required for: forking repos, cloning private forks, pushing code. Without it, git push and gh repo fork will fail.
Workflow
Step 1: Get Parameters
| Parameter | Required | Default | Example |
|---|
| Repository | ✅ | — | INLINECODE4 |
| GitHub username |
✅ | — |
myusername |
| Branch name | ❌ |
(stay on default) |
fix/bug-description |
| Working directory | ❌ |
~/prs/{repo} |
~/dev/{repo} |
| Auth method | ❌ |
GH_TOKEN env var | Token in URL, SSH |
Step 2: Fork
CODEBLOCK1
If fork already exists, this is a no-op. If the user already owns the repo, skip forking.
Step 3: Clone
CODEBLOCK2
Step 4: Configure Upstream Remote
CODEBLOCK3
Step 5: Create Feature Branch
CODEBLOCK4
Branch Naming Conventions
| Type | Pattern | Example |
|---|
| Bug fix | INLINECODE10 | INLINECODE11 |
| Feature |
feat/{short-description} |
feat/add-retry-logic |
| Refactor |
refactor/{short-description} |
refactor/extract-auth-module |
| Review iteration |
fix/{description}-v2 |
fix/tool-guards-v2 |
Step 6: Install Dependencies
Detect the project type and install accordingly:
| Indicator | Language | Install Command |
|---|
| INLINECODE18 / INLINECODE19 | Python | INLINECODE20 or INLINECODE21 |
| INLINECODE22 |
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 |
If full dev install fails (common with native dependencies):
- 1. Install core deps individually
- Skip optional native/GPU deps
- Ensure test framework is installed at minimum
Step 7: Verify
CODEBLOCK5
Automation Script
A helper script is available if this Skill is installed alongside oss-pr-campaign:
CODEBLOCK6
Or implement the same logic step-by-step using the SOP above.
Output
- - Local repo at
~/prs/{repo}/ (or custom directory) on feature branch - Upstream remote configured
- Dependencies installed
- Ready for development
Tips
- - When used as part of a development pipeline, this follows issue-hunter and feeds into dev-test.
- For exploring a codebase without contributing, skip the fork step and clone the original directly.
- Store GH_TOKEN in your shell profile for persistent auth across sessions.
- If working on multiple repos, keep them all under
~/prs/ for easy navigation.
Repo Setup — Fork、Clone 与分支设置
概述
自动化设置本地开发环境,用于贡献或处理 GitHub 仓库。处理完整的 fork → clone → 分支 → 依赖项流程。
使用场景:开源贡献、多仓库开发、新项目上手、代码库探索。
前置条件
bash
gh auth status # 必须显示 Logged in
git --version # 已安装 Git
如果未配置,请要求用户提供:
- 1. GitHub 用户名 — 用于 fork URL 和 clone 路径
- 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})
DEFAULT
BRANCH=${DEFAULTBRANCH:-main}
从最新上游创建分支
git checkout -b {branch
name} 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.py | Python | pip 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. 单独安装核心依赖项
- 跳过可选的原生/GPU 依赖项
- 至少确保安装了测试框架
步骤 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/ 下以便于导航。