# 错误：无法删除在 '/path/to/repo' 检出的分支 'main'

- **ID:** `git/cannot-delete-branch-checked-out`
- **领域:** git
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

尝试删除当前 Git 仓库中已检出的分支。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| git 2.30 | active | — | — |
| git 2.39 | active | — | — |
| git 2.45 | active | — | — |

## 解决方案

1. ```
   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
   ```

## 无效尝试

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