# error: Cannot delete branch 'main' checked out at '/path/to/repo'

- **ID:** `git/cannot-delete-branch-checked-out`
- **Domain:** git
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Attempting to delete the currently checked-out branch in a Git repository.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| git 2.30 | active | — | — |
| git 2.39 | active | — | — |
| git 2.45 | active | — | — |

## Workarounds

1. **Switch to another branch (e.g., 'main' or 'develop') before deleting: git checkout other-branch && git branch -D main** (95% success)
   ```
   Switch to another branch (e.g., 'main' or 'develop') before deleting: git checkout other-branch && git branch -D main
   ```
2. **If the branch is not needed, force delete from a different worktree or after detaching HEAD: git checkout --detach && git branch -D main** (85% success)
   ```
   If the branch is not needed, force delete from a different worktree or after detaching HEAD: git checkout --detach && git branch -D main
   ```

## Dead Ends

- **** — Force delete (-D) also fails on the currently checked-out branch; Git refuses to delete a branch that is active. (95% fail)
- **** — The branch is still checked out in the current working tree; Git checks the repository state, not just the session. (90% fail)
