git
runtime_error
ai_generated
true
fatal: This operation must be run in a work tree
ID: git/detached-head-from-bare-repo
90%Fix Rate
85%Confidence
1Evidence
2024-02-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| git 2.43.0 | active | — | — | — |
| git 2.44.0 | active | — | — | — |
| git 2.45.0 | active | — | — | — |
Root Cause
Attempting to run a command that requires a working tree (like checkout or status) inside a bare repository.
generic中文
尝试在裸仓库中运行需要工作树的命令(如checkout或status)
Official Documentation
https://git-scm.com/docs/git-worktreeWorkarounds
-
95% success Clone the bare repo into a working tree: git clone /path/to/bare.git /tmp/workdir && cd /tmp/workdir && git status
Clone the bare repo into a working tree: git clone /path/to/bare.git /tmp/workdir && cd /tmp/workdir && git status
-
85% success Use 'git worktree add' to create a linked working tree from the bare repo: git worktree add /tmp/workdir main
Use 'git worktree add' to create a linked working tree from the bare repo: git worktree add /tmp/workdir main
中文步骤
Clone the bare repo into a working tree: git clone /path/to/bare.git /tmp/workdir && cd /tmp/workdir && git status
Use 'git worktree add' to create a linked working tree from the bare repo: git worktree add /tmp/workdir main
Dead Ends
Common approaches that don't work:
-
Running 'git checkout main' in a bare repo thinking it will switch branches
95% fail
Bare repos have no working tree; checkout cannot modify files
-
Setting GIT_DIR to a bare repo path and running git status
90% fail
Bare repos store only objects, no index or working tree for status