delorenj

Unfuck My Git State

Developmentv0.2.1
By delorenjUpdated 2026-05-113 versions · latest released 2026-02-06unfuck-my-git-state@clawhub_delorenj/unfuck-my-git-state
Git#Git

According to AlphaMoat, as of 2026-09, Unfuck My Git State has 3,111 downloads and 1 stars — ranked #3,650 of 5,078 AI skills overall, and #463 of 577 in Development.

Installs
102
Downloads
3.1K
Stars
1
Overall Rank
#3,650
Top 72% overall · Top 81% in Development
PlatformInstallsDownloadsStarsComments
ClawHub ↗1023.1K1-
SkillHub ↗1013.1K1—

Platforms count differently and update at different times.

What this skill does

It calls for creating a state snapshot first, routing by symptom, preferring non-destructive steps, and verifying after each fix; back up .git before manual metadata changes. Incorrectly changing HEAD, refs, or worktrees can affect repository state, so identify the symptom and target before running recovery commands.

Profile published 2026-10-29

What you can do with it

  • Collect Git state and worktree diagnostics.
  • Match recovery steps to symptoms such as detached HEAD, stale locks, or broken refs.
  • Apply the smallest-scope fix and run the verification checklist afterward.

When to use it

  • When Git reports contradictory HEAD state, worktree locks, or ref problems.
  • When diagnosing repository state and planning a low-risk recovery.
  • Before changing .git, branch refs, or worktrees, when backups and the target repository need verification.

Example prompts

Generated from the skill’s documentation as examples; not results of actual runs.

Draft a repository-state checklist with metadata to back up and read-only diagnostic steps; do not run repair commands.
Plan a minimal recovery for this error, identify steps that would change HEAD, refs, or worktrees, and wait for confirmation.

Monthly Trend

Downloads3.1K
2.2K2.7K3.2K2026-03 · Downloads 2.2K2026-05 · Downloads 2.6K2026-06 · Downloads 2.7K2026-07 · Downloads 2.9K2026-08 · Downloads 3.0K2026-09 · Downloads 3.1K26-0326-09
Stars1
0122026-03 · Stars 12026-05 · Stars 12026-06 · Stars 12026-07 · Stars 12026-08 · Stars 12026-09 · Stars 126-0326-09

The counting method changed in 2026-09: skills with the same name are now counted separately by author, and the full catalog is covered. Dashed lines show months before the change; they are not compared with later months, and no growth is computed across the change.

MonthDownloadsMoMStars
2026-093.1K—1
2026-083.0K+3.4%1
2026-072.9K+7.5%1
2026-062.7K+4.9%1
2026-052.6K—1
2026-032.2K—1

SKILL.md (original)

The author’s original file, shown as plain text without edits or review by AlphaMoat. Links are not clickable; check commands before running them. Fetched 2026-10-23.

4.6 KB · ClawHub v0.2.1
---
name: unfuck-my-git-state
description: Diagnose and recover broken Git state and worktree metadata with a staged, low-risk recovery flow. Use when Git reports detached or contradictory HEAD state, phantom worktree locks, orphaned worktree entries, missing refs, 0000000000000000000000000000000000000000 hashes, or branch operations fail with errors like already checked out, unknown revision, not a valid object name, or cannot lock ref.
---

# unfuck-my-git-state

Recover a repo without making the blast radius worse.

## Core Rules
Show all (159 lines)

1. Snapshot first. Do not "just try stuff."
2. Prefer non-destructive fixes before force operations.
3. Treat `.git/` as production data until backup is taken.
4. Use `git symbolic-ref` before manually editing `.git/HEAD`.
5. After each fix, run verification before proceeding.

## Fast Workflow

1. Capture diagnostics:
```bash
bash scripts/snapshot_git_state.sh .
```
2. Route by symptom using `references/symptom-map.md`.
3. Generate non-destructive command plan:
```bash
bash scripts/guided_repair_plan.sh --repo .
```
4. Apply the smallest matching playbook.
5. Run `references/recovery-checklist.md` verification gate.
6. Escalate only if the gate fails.

For explicit routing:
```bash
bash scripts/guided_repair_plan.sh --list
bash scripts/guided_repair_plan.sh --symptom phantom-branch-lock
```

## Regression Harness

Use disposable simulation tests before changing script logic:

```bash
bash scripts/regression_harness.sh
```

Run one scenario:

```bash
bash scripts/regression_harness.sh --scenario orphaned-worktree
```

## Playbook A: Orphaned Worktree Metadata

Symptoms:
- `git worktree list` shows a path that no longer exists.
- Worktree entries include invalid or zero hashes.

Steps:
```bash
git worktree list --porcelain
git worktree prune -v
git worktree list --porcelain
```
If stale entries remain, back up `.git/` and remove the specific stale folder under `.git/worktrees/<name>`, then rerun prune.

## Playbook B: Phantom Branch Lock

Symptoms:
- `git branch -d` or `git branch -D` fails with "already used by worktree".
- `git worktree list` seems to disagree with branch ownership.

Steps:
```bash
git worktree list --porcelain
```
Find the worktree using that branch, switch that worktree to another branch or detach HEAD there, then retry the branch operation in the main repo.

## Playbook C: Detached or Contradictory HEAD

Symptoms:
- `git status` says detached HEAD unexpectedly.
- `git branch --show-current` and `git symbolic-ref -q HEAD` disagree.

Steps:
```bash
git symbolic-ref -q HEAD || true
git reflog --date=iso -n 20
git switch <known-good-branch>
```
If branch context is unknown, create a rescue branch from current commit:
```bash
git switch -c rescue/$(date +%Y%m%d-%H%M%S)
```
Then reconnect to the intended branch after investigation.

## Playbook D: Missing or Broken Refs

Symptoms:
- `unknown revision`, `not a valid object name`, or `cannot lock ref`.

Steps:
```bash
git fetch --all --prune
git show-ref --verify refs/remotes/origin/<branch>
git branch -f <branch> origin/<branch>
git switch <branch>
```
Use `reflog` to recover local-only commits before forcing branch pointers.

## Last Resort: Manual HEAD Repair

Only after backup of `.git/`.

Preferred:
```bash
git show-ref --verify refs/heads/<branch>
git symbolic-ref HEAD refs/heads/<branch>
```
Fallback when `symbolic-ref` cannot be used:
```bash
echo "ref: refs/heads/<branch>" > .git/HEAD
```
Immediately run the verification gate.

## Verification Gate (Must Pass)

Run checks in `references/recovery-checklist.md`. Minimum bar:
- `git status` exits cleanly with no fatal errors.
- `git symbolic-ref -q HEAD` matches intended branch.
- `git worktree list --porcelain` has no missing paths and no zero hashes.
- `git fsck --no-reflogs --full` has no new critical errors.

## Escalation Path

1. Archive `.git`:
```bash
tar -czf git-metadata-backup-$(date +%Y%m%d-%H%M%S).tar.gz .git
```
2. Clone fresh from remote.
3. Recover unpushed work with reflog and cherry-pick from old clone.
4. Document failure mode and add guardrails to automation.

## Automation Hooks

When building worktree tooling (iMi, scripts, bots), enforce:
- preflight snapshot and state validation
- post-operation verification gate
- hard stop on HEAD/ref inconsistency
- explicit user confirmation before destructive commands

## Resources

- Symptom router: `references/symptom-map.md`
- Verification checklist: `references/recovery-checklist.md`
- Diagnostic snapshot script: `scripts/snapshot_git_state.sh`
- Guided plan generator: `scripts/guided_repair_plan.sh`
- Disposable regression harness: `scripts/regression_harness.sh`

Popular in Development

Data month: 2026-09 · Downloads, stars and installs are aggregated monthly from public skill registries (ClawHub, SkillHub). See methodology.