You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Create detached worktree (no branch, useful for experiments)
126
+
wt switch -c experiment --detached
127
+
124
128
# Toggle between worktrees
125
129
wt switch feat
126
130
wt switch other
@@ -130,6 +134,23 @@ wt switch - # Back to feat
130
134
wt switch ^
131
135
```
132
136
137
+
**Detached Worktrees:**
138
+
139
+
Detached worktrees are not on any branch - they point directly to a commit. They're useful for temporary work, experiments, or reviewing specific commits without affecting any branches. Each detached worktree preserves the name you give it, so you can easily list, switch to, and manage multiple detached worktrees:
140
+
141
+
```bash
142
+
# Create multiple detached worktrees
143
+
wt switch -c review-pr-123 --detached
144
+
wt switch -c experiment-new-arch --detached
145
+
146
+
# List shows each with its unique name (not generic "detached")
Copy file name to clipboardExpand all lines: tools/wt-worktree/notes.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,6 +154,24 @@ wt-worktree/
154
154
- Tests: Added 6 comprehensive tests covering all options and edge cases
155
155
- Lesson: When implementing operations that process multiple items, use warning/info functions instead of error() to avoid early exit
156
156
157
+
9.**Detached Worktree Name Preservation**
158
+
- Problem: Multiple detached worktrees all showed as "(Detached)" in lists, making them indistinguishable
159
+
- Problem: Couldn't switch to detached worktrees by the name given during `wt switch -c <name> --detached`
160
+
- Solution:
161
+
- Store user-given names in worktree-specific git config using `git config --worktree worktree.name <name>`
162
+
- Retrieve stored names when listing worktrees
163
+
- Enable `extensions.worktreeConfig` to support per-worktree config
164
+
- Implementation Details:
165
+
- Added `enable_worktree_config()`, `set_worktree_name()`, and `get_worktree_name()` functions in git.py
166
+
- Modified `create_worktree()` to store names for detached worktrees
167
+
- Modified `list_worktrees()` to retrieve stored names or fallback to `(detached-<commit>)`
168
+
- Fixed base branch selection: detached worktrees now use HEAD instead of default_base
169
+
- Key Insight: Git's `--worktree` config flag requires `extensions.worktreeConfig` to be enabled first
170
+
- Tests: Added 6 comprehensive tests for detached worktree creation, listing, switching, running commands, and deletion
171
+
- Lesson: Per-worktree config in git requires enabling the worktreeConfig extension, and is the right way to store worktree-specific metadata
172
+
- Backward Compatibility: Added `_infer_name_from_path()` to infer names from path patterns for detached worktrees created before this fix or via raw git commands
0 commit comments