--- name: git-recovery description: Recupera el repositorio de estados inconsistentes (worktrees huérfanos, branches bloqueados) argument-hint: [--aggressive] disable-model-invocation: true user-invocable: true allowed-tools: Bash, Read --- # git-recovery Recupera el repositorio de estados inconsistentes causados por worktrees huérfanos, branches bloqueados o conflictos git. ## Sintaxis ```bash /git-recovery # Recuperación estándar /git-recovery --aggressive # Limpieza agresiva ``` ## Cuándo usar - Errores "exit status 128" al crear worktrees - Git reporta "worktree already exists" - Branches que no se pueden eliminar - Worktrees huérfanos en `git worktree list` ## Flujo ### 1. Diagnóstico inicial ```bash git branch --show-current git status --porcelain ``` ### 2. Análisis de problemas ```bash git worktree list git branch --list git remote -v ``` ### 3. Limpieza de worktrees huérfanos ```bash git worktree prune -v ``` Si existe directorio `worktrees/`: - Verificar cada worktree contra `git worktree list` - Eliminar directorios huérfanos ### 4. Verificar branches bloqueados Para cada branch issue/* o quick/*: - Si está mergeada: `git branch -d ` - Si NO está mergeada: advertir ### 5. Sincronizar con remoto ```bash git checkout master git fetch origin git pull --rebase origin master ``` ### 6. Modo agresivo (solo con --aggressive) ```bash git remote prune origin -v git fsck --full git gc --prune=now rm -f .git/index.lock # si existe ``` ### 7. Verificación final ```bash git status git worktree list git branch --list ``` ## Patrones de error que activan recovery - `exit status 128` - `worktree .* already exists` - `reference is not a tree` - `cannot lock ref` - `index.lock` ## Convenciones - No destructivo por defecto - Modo agresivo solo con flag explícito - Siempre sincroniza con remoto - Preserva cambios locales ## Reglas - NUNCA git reset --hard sin --aggressive - NUNCA eliminar branches no mergeadas automáticamente - SIEMPRE sincronizar con remoto después de limpieza