mcpField
F
fork

fork

github.com/terrylica開発254 回インストール1 日前に更新
リポジトリ

fork について

GitHub の fork リモートと git-town の設定を行い、状態を確認するための段階的なスキルです。fork ワークフローを使うコントリビューター向けで、事前確認、ユーザー承認、操作後の検証を必須とします。

主な機能

  1. 01ツールとリポジトリの事前確認
  2. 02fork とリモートの設定手順
  3. 03git-town によるブランチ運用
  4. 04操作前の確認ゲート
  5. 05リモートと設定の検証

活用シーン

  1. 01fork の作成とリモート設定
  2. 02既存 fork の状態確認
  3. 03リモートまたは git-town 設定の問題調査

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/terrylica/cc-skills --skill fork

インストール後、Claude Code で/forkを入力して読み込まれたか確認します。

同梱ファイルreferences/evolution-log.md

詳細

Git-Town フォークワークフロー — 必ずお読みください

思い込みで操作しないでください。まずこのファイルをお読みください。

これは手順を厳守し、各段階にゲートを設けたワークフローです。すべてのステップで以下が必要です。

  1. 事前チェック - 前提条件を確認します
  2. ユーザーの確認 - 操作の前にAskUserQuestionを行います
  3. 検証 - 操作が成功したことを確認します

自己進化型スキル:このスキルは使用を通じて改善されます。手順が誤っている、パラメーターが変わっている、回避策が必要だった場合は、先送りにせず、すぐにこのファイルを修正してください。更新するのは、実際に再現可能な問題がある場合に限ります。

⛔ ワークフローの基本方針

GIT-TOWNが標準です。ブランチ操作でRAW GITを使うことは禁止です。

操作✅ 使用する❌ 絶対に使用しない
ブランチの作成git town hackgit checkout -b
ブランチの更新git town syncgit pull、git merge
PRの作成git town propose手動のウェブUI
PRのマージgit town shipgit merge + push
ブランチの切り替えgit town switchgit checkout

例外:コミット、ステージング、ログの表示、diffにはraw gitを使用できます(git-townはこれらを置き換えません)。


フェーズ0:事前チェック — 最初に必ず実行

ほかの操作を行う前に実行してください。

ステップ0.1:TodoWriteを作成
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
ステップ0.2:git-townのインストールを確認
/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: false

「Yes」の場合:brew install git-townを実行し、再確認します。 「No」の場合:停止してください。先に進まないでください。

ステップ0.3:GitHub CLIのインストールを確認
/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
ステップ0.4:リポジトリのコンテキストを検出

AskUserQuestionを行う前に、検出スクリプトを実行してください。

/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
ステップ0.5:GitHubアカウントを検出
/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

フェーズ1:ゲート — 検出結果を提示

必須:検出結果をすべて提示し、ユーザーから明示的な確認を得てください。

ステップ1.1:検出結果をまとめる

検出された状態の概要表を作成します。

項目検出値状態
リポジトリ{owner}/{repo}✅/❌
originリモート{url}✅/❌
upstreamリモート{url}✅/❌/MISSING
GitHubアカウント{username}✅/❌
git-townの設定yes/no✅/❌
ステップ1.2:ワークフローの種類を判定
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: false
ステップ1.3:リモートURLを確認(新しいフォークの場合)
AskUserQuestion 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: false
ステップ1.4:フォーク先を確認
AskUserQuestion 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: false
ステップ1.5:最終確認ゲート
AskUserQuestion 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

「No, abort」の場合:停止してください。先に進まないでください。


フェーズ2:フォークのセットアップを実行

ステップ2.1:フォークを作成(必要な場合)

フォークが存在しない場合のみ:

/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'
ステップ2.2:リモートを設定

originをフォークに設定(SSHを優先):

git remote set-url origin [email protected]:{fork_owner}/{repo}.git

upstreamを追加(存在しない場合):

git remote add upstream [email protected]:{upstream_owner}/{repo}.git

または、upstreamを修正(誤っている場合):

git remote set-url upstream [email protected]:{upstream_owner}/{repo}.git
ステップ2.3:git-townを初期化
/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

フェーズ3:検証

ステップ3.1:リモート設定を確認
/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
ステップ3.2:git-townの設定を確認
/usr/bin/env bash -c 'git town config'

想定される出力には、以下が表示されます。

  • sync-upstream: true
  • dev-remote: origin
ステップ3.3:git-town syncをテスト
AskUserQuestion 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: false

テストを選択した場合:

git town sync --dry-run  # or without --dry-run
ステップ3.4:ワークフローのチートシートを表示

最後に必ず表示してください。

## ✅ 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 [email protected]:{fork_owner}/{repo}.git
git remote add upstream [email protected]:{upstream_owner}/{repo}.git

引数

  • [upstream-url] - 任意:フォーク元リポジトリの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

トラブルシューティング

問題原因解決策
gh fork failedすでにフォーク済み、またはアクセス権がありません--check を使って既存のフォークを確認します
Permission deniedSSH キーが GitHub に追加されていませんSSH キーを追加するか、HTTPS URL を使います
Remote already existsOrigin/upstream がすでに設定されていますgit remote set-url を使って更新します
Fork not detectedOrigin URL が一致しませんgit remote -v で不一致を確認します
Upstream sync fails履歴が分岐していますgit town sync で調整します
"Not a fork" errorリポジトリは origin であり、フォークではありませんまず gh repo fork でフォークします

実行後の振り返り

このスキルの実行が完了したら、タスクを終了する前に振り返ります。

  1. 現在の場所を確認します。 — 編集前に、この SKILL.md の正規パスを確認します(このスキルの名前で Glob を実行します)。修正対象はこのファイルと兄弟の references/ のみです。他のドキュメントは対象にしません。
  2. 何が失敗しましたか? — 原因となった指示を修正します。再発する可能性がある場合は、アンチパターンとして追加します。
  3. 予想以上にうまくいったことは何ですか? — 推奨プラクティスとして取り入れます。その理由も記録します。
  4. 何が現状とずれていましたか? — 実態に合わなくなったスクリプト、リファレンス、外部依存関係は、今すぐ修正します。
  5. 記録します。 — 変更のたびに、きっかけ、修正内容、根拠を含む進化ログのエントリーを追加します。

先送りしないでください。次回の実行では、残された状態が引き継がれます。

コメント