# 致命错误：此操作必须在工作树中运行

- **ID:** `git/detached-head-from-bare-repo`
- **领域:** git
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

尝试在裸仓库中运行需要工作树的命令（如checkout或status）

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| git 2.43.0 | active | — | — |
| git 2.44.0 | active | — | — |
| git 2.45.0 | active | — | — |

## 解决方案

1. ```
   Clone the bare repo into a working tree: git clone /path/to/bare.git /tmp/workdir && cd /tmp/workdir && git status
   ```
2. ```
   Use 'git worktree add' to create a linked working tree from the bare repo: git worktree add /tmp/workdir main
   ```

## 无效尝试

- **Running 'git checkout main' in a bare repo thinking it will switch branches** — Bare repos have no working tree; checkout cannot modify files (95% 失败率)
- **Setting GIT_DIR to a bare repo path and running git status** — Bare repos store only objects, no index or working tree for status (90% 失败率)
