Fork, clone, and set up a GitHub repository for development or contribution. Handles fork creation, clone with authentication, upstream remote configuration,...
---
name: repo-setup
description: "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."
---
# 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
```bash
gh auth status # Must show "Logged in"
git --version # Git installed
```
If not configured, ask the user to provide:
1. **GitHub username** — used for fork URLs and clone paths
2. **GitHub token** — run `gh auth login` or set `export GH_TOKEN=<token>`
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 | ✅ | — | `owner/repo` |
| 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
```bash
gh repo fork {owner}/{repo} --clone=false
```
If fork already exists, this is a no-op. If the user already owns the repo, skip forking.
### Step 3: Clone
```bash
WORKDIR="${WORK_BASE:-$HOME/prs}/{repo_name}"
if [ -d "$WORKDIR" ]; then
cd "$WORKDIR"
git fetch --all
else
mkdir -p "$(dirname "$WORKDIR")"
# With token auth
git clone "https://${GH_TOKEN}@github.com/${username}/${repo_name}.git" "$WORKDIR"
# Or with SSH
# git clone "git@github.com:${username}/${repo_name}.git" "$WORKDIR"
cd "$WORKDIR"
fi
```
### Step 4: Configure Upstream Remote
```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
```
### Step 5: Create Feature Branch
```bash
# Detect default branch
DEFAULT_BRANCH=$(git remote show upstream 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}')
DEFAULT_BRANCH="${DEFAULT_BRANCH:-main}"
# Create branch from latest upstream
git checkout -b {branch_name} upstream/$DEFAULT_BRANCH
```
### Branch Naming Conventions
| Type | Pattern | Example |
|------|---------|---------|
| Bug fix | `fix/{short-description}` | `fix/null-pointer-on-empty-list` |
| 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 |
|-----------|----------|----------------|
| `pyproject.toml` / `setup.py` | Python | `pip install -e ".[dev]"` or `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` |
**If full dev install fails** (common with native dependencies):
1. Install core deps individually
2. Skip optional native/GPU deps
3. Ensure test framework is installed at minimum
### Step 7: Verify
```bash
# Check setup
echo "Directory: $(pwd)"
echo "Branch: $(git branch --show-current)"
echo "Upstream: $(git remote get-url upstream)"
echo "Fork: $(git remote get-url origin)"
# Quick build/import test
# Python: python -c "import {package}"
# Node: npm run build (if applicable)
# Go: go build ./...
```
## Automation Script
A helper script is available if this Skill is installed alongside **oss-pr-campaign**:
```bash
# One-liner setup
scripts/setup_repo.sh owner/repo username fix/branch-name
```
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.
don't have the plugin yet? install it then click "run inline in claude" again.
restructured into implexa's six-component format, made decision logic explicit for fork creation and branch handling, documented gh_token as external connection with auth edge cases (expiry, rate limits), added network timeout and corruption handling, clarified build verification per language, and added explicit output contract with directory structure and outcome signals.
automate the full pipeline for setting up a local development environment on a github repository. this skill handles forking (if needed), cloning with authentication, configuring upstream remotes, creating feature branches from the latest upstream state, and installing language-specific dependencies. use this when starting work on an open-source project, setting up a multi-repo development environment, onboarding to a new codebase, or exploring unfamiliar projects locally.
required parameters:
owner/repo: github repository identifier (e.g., torvalds/linux, nodejs/node)github_username: your github account username, used for fork urls and clone pathsgh_token: github personal access token, obtained via gh auth login. store as export GH_TOKEN=<token> in your shell profile or .env. required for: forking private repos, cloning private forks, pushing commits back to your fork. without it, git push and gh repo fork will fail with auth errors.optional parameters:
branch_name: name for your feature branch (default: stay on upstream default branch). follow naming conventions: fix/description, feat/description, refactor/descriptionworking_directory: local path where repo clones (default: ~/prs/{repo_name}). useful for multi-repo setups or non-standard directory layoutsexternal connections:
gh): must be installed and authenticated. check with gh auth status$PATH. check with git --versionedge cases to handle:
git config http.postBuffer 524288000gh repo fork is a no-op, which is correct behaviorstep 1: validate prerequisites
input: system state
gh auth status and confirm output shows "logged in to github.com as {username}"git --version and confirm git is installedGH_TOKEN environment variable is set (or token is in gh config)output: confirmation that tooling is available, or explicit error asking user to run gh auth login
step 2: resolve repository ownership and fork decision
input: owner/repo, github_username
gh repo view owner/repo) to get repo metadatausername/repo exist and is it a fork of owner/repo?)decision: go to step 3 (fork) if user does not own the repo. skip to step 4 (clone user's fork) if fork exists. if user owns the original repo, skip forking entirely and clone their own repo.
output: boolean flag (fork_exists) and actual fork url to use
step 3: fork repository (conditional)
input: fork_exists flag, owner/repo, gh_token
gh repo fork owner/repo --clone=falsehandle errors:
output: confirmation that fork exists at https://github.com/{github_username}/{repo_name}
step 4: clone or fetch
input: working_directory, github_username, repo_name, gh_token
working_directory, cd into it and run git fetch --all to refreshmkdir -p "$(dirname "$working_directory")"git clone "https://${GH_TOKEN}@github.com/${github_username}/${repo_name}.git" "$working_directory"git clone "git@github.com:${github_username}/${repo_name}.git" "$working_directory"handle errors:
GH_TOKEN is set and validoutput: repo cloned and ready at working_directory, with origin remote pointing to user's fork
step 5: configure upstream remote
input: repo already cloned at working_directory, owner, repo_name
working_directorygit remote get-url upstreamgit remote add upstream "https://github.com/${owner}/${repo_name}.git"git fetch upstreamhandle errors:
git remote remove upstream && git remote add upstream ...output: upstream remote configured, all upstream refs available locally
step 6: create and checkout feature branch (conditional)
input: branch_name (optional), upstream remote, repo default branch
git remote show upstream 2>/dev/null | grep 'HEAD branch' | awk '{print $NF}', fallback to main if not foundbranch_name is provided:git checkout -b {branch_name} upstream/{DEFAULT_BRANCH}branch_name is not provided:handle errors:
git fetch upstream --alloutput: on feature branch, synced to latest upstream state
step 7: detect project type and install dependencies
input: repo at working_directory, directory listing
scan for language indicators in this order (stop at first match):
pyproject.toml (python, modern): pip install -e ".[dev]" or fallback to pip install -e .setup.py (python, legacy): pip install -e ".[dev]" or fallback to pip install -e .requirements.txt (python): pip install -r requirements.txtpackage.json (node): npm installgo.mod (go): go mod downloadCargo.toml (rust): cargo buildpom.xml (java/maven): mvn install -DskipTestsbuild.gradle (java/kotlin/gradle): ./gradlew build -x testif dev install fails (common with native dependencies or missing system libs):
if no indicators found, output message: "no recognized dependency manager found. skipping dependency installation. verify manually if needed."
output: dependencies installed or skipped with clear explanation
step 8: verify setup
input: repo at working_directory
working_directorypwdgit branch --show-currentgit remote get-url upstreamgit remote get-url originpython -c "import {inferred_package_name}" (check if main module imports cleanly)npm run build (if build script exists) or npm test --dry-rungo build ./...cargo checkmvn compile (without install to skip tests)output: summary of repo state and confirmation that code compiles/imports
fork creation: if user already owns a fork of the target repo, skip fork step (no-op). if user owns the original repo, skip forking and clone their own repo directly.
clone method:
if gh_token is set, use https clone with token injected into url. if user specifies ssh preference, use ssh clone url instead (requires ssh key configured).
branch creation:
if branch_name is provided, create feature branch from latest upstream default. if not provided, stay on the upstream default branch (typically main). user must manually create and checkout a branch before committing.
dependency installation: if project type is detected (pyproject.toml, package.json, go.mod, etc.), run appropriate install command. if install fails partway through, attempt to install core deps only and continue. if no project type is detected, skip dependency installation and warn user. if no language runtime is available (e.g., python not installed), fail with message directing user to install runtime.
retry on failure:
if network timeout occurs during clone or fetch, retry once after 10 seconds. if auth fails, prompt user to refresh GH_TOKEN and rerun. if branch creation fails due to existing branch, prompt user to rename or delete the existing branch.
success state:
{working_directory} (default: ~/prs/{repo_name})origin remoteupstream remote with all refs fetched{branch_name} (if provided), tracking upstream default branch, or current upstream default (if no branch provided)git remote -v and git branch -vvfile/directory structure:
~/prs/{repo_name}/
├── .git/
│ ├── refs/remotes/
│ │ ├── origin/
│ │ └── upstream/
│ └── config (contains origin and upstream urls)
├── {project files}
└── node_modules/ or .venv/ or other language-specific artifacts (if installed)
data format: all output is text-based. final verification prints human-readable summary of git config and branch state.
user knows the skill worked when:
git remote -v shows two remotes: origin (user's fork) and upstream (original repo)git log upstream/{default_branch} -1 shows recent commits from the original repogit status shows "nothing to commit")if any of these fail, the skill prints explicit error with remediation steps.