recovering-from-bad-git-state

Diagnose and recover corrupted git state, orphaned worktrees, and inconsistent branch references.

14|1|Updated Oct 22, 2025
One-click install
npx skills add https://github.com/delorenj/skills --skill recovering-from-bad-git-state
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: recovering-from-bad-git-state
Source: https://github.com/delorenj/skills/tree/main/recovering-from-bad-git-state
Command: npx skills add https://github.com/delorenj/skills --skill recovering-from-bad-git-state

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Techniques for diagnosing and recovering from corrupted git state, orphaned worktrees, and inconsistent branch references.

Core Features & Use Cases

  • State validation and corruption type identification
  • Recovery operations for HEAD, worktrees, and branch locks
  • Prevention patterns to avoid future issues

Quick Start

Use this skill to diagnose and recover when HEAD is corrupted, HEAD points to a non-existent branch, or worktrees are orphaned.

Frequently Asked Questions about recovering-from-bad-git-state

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a corrupted git HEAD that points to a non-existent branch?

Corrupted HEAD occurs when .git/HEAD references a branch that no longer exists. Validate your repository state, identify the corruption type, then reset HEAD to a valid branch reference using targeted recovery procedures that restore consistency between HEAD and branch refs.

What should I do if git reports orphaned worktrees after a crash or incomplete cleanup?

Orphaned worktrees are worktree entries that reference deleted directories. Diagnose which worktrees are phantom using validation checks, then prune them safely to remove stale entries and restore repository consistency without affecting active worktrees.

How can I detect and resolve inconsistent branch references in my local repository?

Branch reference inconsistencies occur when HEAD, branch files, and packed-refs fall out of sync. Use state validation to identify corruption type, then apply alignment procedures to reconcile conflicting references and restore a consistent repository state.

Can I prevent git corruption issues from happening again after recovery?

Yes. Prevention patterns include integration hooks that validate repository state during common operations, safe worktree management practices, and HEAD consistency checks. Implementing these patterns reduces the likelihood of future corruption.

What's the fastest way to diagnose why my git repository is in a bad state?

Run state validation checks to identify corruption type—whether HEAD is broken, worktrees are orphaned, or branch locks conflict. Fast corruption-type identification pinpoints the exact recovery procedure needed, saving time on manual debugging.

Do I need special tools or just git commands to recover from corruption?

Recovery uses standard git operations with validation logic to identify corruption safely. You need git itself and access to your local repository; no external dependencies are required to diagnose and apply targeted recovery procedures.