---
name: step-init
description: Initialize GitFlow configuration and branches
next_step: null
---

# Step: INIT - Initialize GitFlow

## YOUR TASK:

Set up GitFlow configuration, create main/develop branches, and configure worktree structure.

**ULTRA THINK before creating configuration.**

---

## EXECUTION SEQUENCE:

### 1. Detect Environment

```bash
# Check if already initialized
[ -f ".claude/gitflow/config.json" ] && {
  echo "GitFlow already initialized"
  # Show current config and ask to reinitialize
}

# Detect git provider
REMOTE_URL=$(git remote get-url origin 2>/dev/null || echo "")
if [[ "$REMOTE_URL" == *"github.com"* ]]; then
  GIT_PROVIDER="github"
elif [[ "$REMOTE_URL" == *"dev.azure.com"* ]]; then
  GIT_PROVIDER="azuredevops"
else
  GIT_PROVIDER="unknown"
fi

# Detect existing branches
HAS_MAIN=$(git branch -r --list "origin/main" | wc -l)
HAS_DEVELOP=$(git branch -r --list "origin/develop" | wc -l)
```

### 2. Configuration Questions

```yaml
AskUserQuestion:
  - header: "Mode"
    question: "How do you want to set up GitFlow?"
    options:
      - label: "Quick Setup (Recommended)"
        description: "Auto-detect settings, create branches"
      - label: "Custom Setup"
        description: "Configure each option manually"
      - label: "Existing Config"
        description: "Use existing .claude/gitflow/config.json"

  - header: "Worktrees"
    question: "How should worktrees be organized?"
    options:
      - label: "Organized (Recommended)"
        description: "../features/, ../releases/, ../hotfixes/"
      - label: "Adjacent"
        description: "../worktrees/{type}/"
      - label: "Disabled"
        description: "No worktrees, use git checkout"
```

### 3. Create Branches (if needed)

```bash
# Ensure we have main
[ "$HAS_MAIN" -eq 0 ] && {
  git checkout -b main
  git push -u origin main
}

# Ensure we have develop
[ "$HAS_DEVELOP" -eq 0 ] && {
  git checkout main
  git checkout -b develop
  git push -u origin develop
}
```

### 4. Create Directory Structure

```bash
mkdir -p .claude/gitflow/{plans,logs,cache,backup}

# Create worktree directories if mode != disabled
case "$WORKTREE_MODE" in
  organized)
    mkdir -p ../features ../releases ../hotfixes
    ;;
  adjacent)
    mkdir -p ../worktrees/{features,releases,hotfixes}
    ;;
esac
```

### 5. Create Configuration

**Write `.claude/gitflow/config.json`:**

```json
{
  "version": "2.0.0",
  "repository": {
    "name": "{repo_name}",
    "defaultBranch": "main",
    "remoteUrl": "{remote_url}"
  },
  "git": {
    "provider": "{github|azuredevops}",
    "branches": {
      "main": "main",
      "develop": "develop"
    },
    "prefixes": {
      "feature": "feature/",
      "release": "release/",
      "hotfix": "hotfix/"
    }
  },
  "worktrees": {
    "enabled": true,
    "mode": "{organized|adjacent|disabled}",
    "structure": {
      "features": "../features",
      "releases": "../releases",
      "hotfixes": "../hotfixes"
    }
  },
  "versioning": {
    "strategy": "semver",
    "current": "{X.Y.Z}",
    "tagPrefix": "v",
    "sources": ["csproj", "package.json", "VERSION"]
  },
  "efcore": {
    "enabled": true,
    "validateOnCommit": true,
    "blockDestructive": true,
    "migrationNaming": "{context}_v{version}_{sequence}_{Description}"
  },
  "workflow": {
    "push": {
      "afterCommit": "worktree"
    },
    "pr": {
      "autoLabels": true,
      "requireReview": true
    }
  },
  "language": {
    "code": "en"
  }
}
```

### 6. Detect Version

```bash
# Priority: csproj > Directory.Build.props > package.json > VERSION > tag
VERSION=$(grep -oP '<Version>\K[^<]+' *.csproj 2>/dev/null | head -1)
[ -z "$VERSION" ] && VERSION=$(grep -oP '<Version>\K[^<]+' Directory.Build.props 2>/dev/null)
[ -z "$VERSION" ] && VERSION=$(grep -oP '"version":\s*"\K[^"]+' package.json 2>/dev/null)
[ -z "$VERSION" ] && VERSION=$(cat VERSION 2>/dev/null)
[ -z "$VERSION" ] && VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//')
[ -z "$VERSION" ] && VERSION="0.1.0"
```

### 7. Summary

```
╔══════════════════════════════════════════════════════════════════╗
║                    GITFLOW INITIALIZED                            ║
╠══════════════════════════════════════════════════════════════════╣
║  Repository: {repo_name}                                          ║
║  Provider:   {github|azuredevops}                                 ║
║  Version:    {X.Y.Z}                                              ║
╠══════════════════════════════════════════════════════════════════╣
║  Branches:                                                        ║
║  - main:    ✅ Ready                                              ║
║  - develop: ✅ Ready                                              ║
╠══════════════════════════════════════════════════════════════════╣
║  Worktrees: {mode}                                                ║
║  - ../features/  (for feature branches)                           ║
║  - ../releases/  (for release branches)                           ║
║  - ../hotfixes/  (for hotfix branches)                            ║
╠══════════════════════════════════════════════════════════════════╣
║  Config: .claude/gitflow/config.json                              ║
╠══════════════════════════════════════════════════════════════════╣
║  NEXT: /gitflow start feature <name>                              ║
╚══════════════════════════════════════════════════════════════════╝
```

---

## SUCCESS CRITERIA:

- Configuration file created
- main and develop branches exist
- Worktree directories created (if enabled)
- Version detected and stored

## NEXT STEP:

Init is standalone. User can now run `/gitflow start feature <name>`.
