Loading...
Loading...
Create or configure a fork workflow with git-town. Preflight checks at every step. TRIGGERS - fork repo, setup fork, git-town fork, create fork, fork workflow, upstream setup.
npx skill4agent add terrylica/cc-skills fork| Operation | ✅ Use | ❌ Never Use |
|---|---|---|
| Create branch | | |
| Update branch | | |
| Create PR | | Manual web UI |
| Merge PR | | |
| Switch branch | | |
TodoWrite with todos:
- "[Fork] Phase 0: Check git-town installation" | in_progress
- "[Fork] Phase 0: Check GitHub CLI installation" | pending
- "[Fork] Phase 0: Detect current repository context" | pending
- "[Fork] Phase 0: Detect existing remotes" | pending
- "[Fork] Phase 0: Detect GitHub account(s)" | pending
- "[Fork] Phase 1: GATE - Present findings and get user confirmation" | pending
- "[Fork] Phase 2: Create fork (if needed)" | pending
- "[Fork] Phase 2: Configure remotes" | pending
- "[Fork] Phase 2: Initialize git-town" | pending
- "[Fork] Phase 3: Validate setup" | pending
- "[Fork] Phase 3: Display workflow cheatsheet" | pending/usr/bin/env bash -c 'which git-town && git-town --version'AskUserQuestion with questions:
- question: "git-town is not installed. Would you like to install it now?"
header: "Install"
options:
- label: "Yes, install via Homebrew (Recommended)"
description: "Run: brew install git-town"
- label: "No, abort workflow"
description: "Cannot proceed without git-town"
multiSelect: falsebrew install git-town/usr/bin/env bash -c 'which gh && gh --version && gh auth status'AskUserQuestion with questions:
- question: "GitHub CLI is required for fork operations. How to proceed?"
header: "GitHub CLI"
options:
- label: "Install and authenticate (Recommended)"
description: "Run: brew install gh && gh auth login"
- label: "I'll handle this manually"
description: "Provide instructions and exit"
multiSelect: false/usr/bin/env bash << 'DETECT_REPO_EOF'
echo "=== REPOSITORY DETECTION ==="
# Check if in git repo
if ! git rev-parse --git-dir &>/dev/null; then
echo "ERROR: Not in a git repository"
exit 1
fi
# Detect remotes
echo "--- Existing Remotes ---"
git remote -v
# Detect current branch
echo "--- Current Branch ---"
git branch --show-current
# Detect repo URL patterns
echo "--- Remote URLs ---"
ORIGIN_URL=$(git remote get-url origin 2>/dev/null || echo "NONE")
UPSTREAM_URL=$(git remote get-url upstream 2>/dev/null || echo "NONE")
echo "origin: $ORIGIN_URL"
echo "upstream: $UPSTREAM_URL"
# Parse GitHub owner/repo from URLs
if [[ "$ORIGIN_URL" =~ github\.com[:/]([^/]+)/([^/.]+) ]]; then
echo "ORIGIN_OWNER=${BASH_REMATCH[1]}"
echo "ORIGIN_REPO=${BASH_REMATCH[2]%.git}"
fi
if [[ "$UPSTREAM_URL" =~ github\.com[:/]([^/]+)/([^/.]+) ]]; then
echo "UPSTREAM_OWNER=${BASH_REMATCH[1]}"
echo "UPSTREAM_REPO=${BASH_REMATCH[2]%.git}"
fi
# Check git-town config
echo "--- Git-Town Config ---"
git town config 2>/dev/null || echo "git-town not configured"
DETECT_REPO_EOF/usr/bin/env bash << 'DETECT_ACCOUNT_EOF'
echo "=== GITHUB ACCOUNT DETECTION ==="
# Method 1: gh CLI auth status
echo "--- gh CLI Account ---"
GH_USER=$(gh api user --jq '.login' 2>/dev/null || echo "NONE")
echo "gh auth user: $GH_USER"
# Method 2: SSH config
echo "--- SSH Config Hosts ---"
grep -E "^Host github" ~/.ssh/config 2>/dev/null | head -5 || echo "No GitHub SSH hosts"
# Method 3: Git global config
echo "--- Git Global Config ---"
git config --global user.name 2>/dev/null || echo "No global user.name"
git config --global user.email 2>/dev/null || echo "No global user.email"
# Method 4: mise env (if available)
echo "--- mise env ---"
mise env 2>/dev/null | grep -i github || echo "No GitHub vars in mise"
DETECT_ACCOUNT_EOF| Aspect | Detected Value | Status |
|---|---|---|
| Repository | {owner}/{repo} | ✅/❌ |
| Origin remote | {url} | ✅/❌ |
| Upstream remote | {url} | ✅/❌/MISSING |
| GitHub account | {username} | ✅/❌ |
| git-town configured | yes/no | ✅/❌ |
AskUserQuestion with questions:
- question: "What fork workflow do you need?"
header: "Workflow"
options:
- label: "Fresh fork - Create new fork from upstream"
description: "You want to fork someone else's repo to contribute"
- label: "Fix existing - Reconfigure existing fork's remotes"
description: "Origin/upstream are misconfigured, need to fix"
- label: "Verify only - Check current setup is correct"
description: "Just validate, don't change anything"
multiSelect: falseAskUserQuestion with questions:
- question: "Confirm the upstream repository (the original you're forking FROM):"
header: "Upstream"
options:
- label: "{detected_upstream_owner}/{detected_upstream_repo} (Detected)"
description: "Detected from current remotes"
- label: "Enter different URL"
description: "I want to fork a different repository"
multiSelect: falseAskUserQuestion with questions:
- question: "Where should the fork be created?"
header: "Fork Owner"
options:
- label: "{gh_auth_user} (Your account - Recommended)"
description: "Fork to your personal GitHub account"
- label: "Organization account"
description: "Fork to a GitHub organization you have access to"
multiSelect: falseAskUserQuestion with questions:
- question: "Ready to proceed with fork setup?"
header: "Confirm"
options:
- label: "Yes, create/configure fork"
description: "Proceed with: upstream={upstream_url}, fork_owner={fork_owner}"
- label: "No, abort"
description: "Cancel and make no changes"
multiSelect: false/usr/bin/env bash -c 'gh repo fork {upstream_owner}/{upstream_repo} --clone=false --remote=false'/usr/bin/env bash -c 'gh repo view {fork_owner}/{repo} --json url'git remote set-url origin git@github.com:{fork_owner}/{repo}.gitgit remote add upstream git@github.com:{upstream_owner}/{repo}.gitgit remote set-url upstream git@github.com:{upstream_owner}/{repo}.git/usr/bin/env bash << 'INIT_GITTOWN_EOF'
# Initialize git-town with fork settings
git town config setup
# Ensure sync-upstream is enabled
git config git-town.sync-upstream true
# Set dev-remote to origin (your fork)
git config git-town.dev-remote origin
INIT_GITTOWN_EOF/usr/bin/env bash << 'VALIDATE_REMOTES_EOF'
echo "=== REMOTE VALIDATION ==="
ORIGIN=$(git remote get-url origin)
UPSTREAM=$(git remote get-url upstream)
echo "origin: $ORIGIN"
echo "upstream: $UPSTREAM"
# Validate origin points to fork owner
if [[ "$ORIGIN" =~ {fork_owner} ]]; then
echo "✅ origin correctly points to your fork"
else
echo "❌ origin does NOT point to your fork"
exit 1
fi
# Validate upstream points to original
if [[ "$UPSTREAM" =~ {upstream_owner} ]]; then
echo "✅ upstream correctly points to original repo"
else
echo "❌ upstream does NOT point to original repo"
exit 1
fi
VALIDATE_REMOTES_EOF/usr/bin/env bash -c 'git town config'sync-upstream: truedev-remote: originAskUserQuestion with questions:
- question: "Run a test sync to verify everything works?"
header: "Test"
options:
- label: "Yes, run git town sync --dry-run"
description: "Preview what sync would do (safe)"
- label: "Yes, run git town sync for real"
description: "Actually sync branches"
- label: "Skip test"
description: "I'll test manually later"
multiSelect: falsegit town sync --dry-run # or without --dry-run## ✅ Fork Workflow Configured Successfully
### Daily Commands (USE THESE, NOT RAW GIT)
| Task | Command |
| --------------------- | ---------------------------- |
| Create feature branch | `git town hack feature-name` |
| Update all branches | `git town sync` |
| Create PR to upstream | `git town propose` |
| Merge approved PR | `git town ship` |
| Switch branches | `git town switch` |
### ⚠️ FORBIDDEN (Will Break Workflow)
| ❌ Never Use | ✅ Use Instead |
| ---------------------- | ---------------------------------- |
| `git checkout -b` | `git town hack` |
| `git pull` | `git town sync` |
| `git merge` | `git town sync` or `git town ship` |
| `git push origin main` | `git town sync` |
### Quick Reference
- **Sync with upstream**: `git town sync` (automatic)
- **Create stacked branches**: `git town append child-feature`
- **Undo last git-town command**: `git town undo`
- **See branch hierarchy**: `git town branch`AskUserQuestion with questions:
- question: "Fork creation failed. How to proceed?"
header: "Error"
options:
- label: "Retry"
description: "Try creating the fork again"
- label: "Fork exists - configure existing"
description: "Fork already exists, just configure remotes"
- label: "Abort"
description: "Cancel and investigate manually"
multiSelect: false# Manual fix commands:
git remote set-url origin git@github.com:{fork_owner}/{repo}.git
git remote add upstream git@github.com:{upstream_owner}/{repo}.git[upstream-url]--check--fix# Fork a new repository
/git-town-workflow:fork https://github.com/EonLabs-Spartan/alpha-forge
# Check existing fork setup
/git-town-workflow:fork --check
# Auto-fix misconfigured remotes
/git-town-workflow:fork --fix| Issue | Cause | Solution |
|---|---|---|
| gh fork failed | Already forked or no access | Use |
| Permission denied | SSH key not added to GitHub | Add SSH key or use HTTPS URL |
| Remote already exists | Origin/upstream already set | Use |
| Fork not detected | Origin URL doesn't match | Check |
| Upstream sync fails | Diverged histories | |
| "Not a fork" error | Repo is origin, not a fork | Fork first via |