git-worktree-organize 1.0.13 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +247 -26
- package/dist/cli.js +767 -110
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
# git-worktree-organize
|
|
2
2
|
|
|
3
|
-
Convert any git repository into
|
|
3
|
+
Convert any git repository into a bare-hub worktree layout where every branch lives in its own directory. No more stashing, no more switching.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> **Use at your own risk.** This tool modifies your git repository structure. Always ensure you have a copy of important repositories before running it.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
> **Opinionated layout.** This tool enforces a specific structure where every branch is a sibling directory under a single hub root. If you prefer a different worktree arrangement, this tool may not be for you. See [Why this layout?](#why-this-layout) for the rationale.
|
|
8
|
+
|
|
9
|
+
## The target layout
|
|
8
10
|
|
|
9
11
|
```
|
|
10
|
-
|
|
12
|
+
myrepo/
|
|
11
13
|
├── .bare/ ← bare git repo (the actual git database)
|
|
12
14
|
├── .git ← plain file: "gitdir: ./.bare"
|
|
13
15
|
├── main/ ← worktree for the main branch
|
|
14
|
-
└── feature-x/
|
|
16
|
+
└── feature-x/ ← worktree for each other branch
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
Each branch directory is a fully functional working tree. Open them in separate terminals or IDE windows simultaneously
|
|
19
|
+
Each branch directory is a fully functional working tree. Open them in separate terminals or IDE windows simultaneously.
|
|
18
20
|
|
|
19
|
-
The `.git` file at the hub root
|
|
21
|
+
The `.git` file at the hub root means `git worktree list` (and any git command) works from **anywhere** -- the hub root, any worktree directory, or even nested subdirectories. IDEs, linters, and other tools that walk up looking for `.git` also find the repo correctly.
|
|
20
22
|
|
|
21
23
|
## Installation
|
|
22
24
|
|
|
@@ -37,48 +39,267 @@ git-worktree-organize <source> [destination]
|
|
|
37
39
|
git-worktree-organize <source> [destination]
|
|
38
40
|
```
|
|
39
41
|
|
|
40
|
-
| Argument | Description
|
|
41
|
-
|
|
42
|
-
| `source` | Path to the existing git repository to migrate
|
|
43
|
-
| `destination` | Target hub directory (
|
|
42
|
+
| Argument | Description |
|
|
43
|
+
|---------------|------------------------------------------------------------|
|
|
44
|
+
| `source` | Path to the existing git repository to migrate |
|
|
45
|
+
| `destination` | Target hub directory (omit for in-place migration) |
|
|
44
46
|
|
|
45
47
|
The tool shows a preview of what will be created and asks for confirmation before making any changes.
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
### In-place migration
|
|
50
|
+
|
|
51
|
+
When no destination is provided, the tool prompts to migrate in place:
|
|
48
52
|
|
|
49
|
-
|
|
53
|
+
1. Renames `<source>` to `<source>.old`
|
|
54
|
+
2. Creates the hub at the original `<source>` path
|
|
50
55
|
|
|
51
56
|
```sh
|
|
52
|
-
git-worktree-organize /projects/myrepo
|
|
57
|
+
git-worktree-organize /projects/myrepo
|
|
53
58
|
```
|
|
54
59
|
|
|
55
60
|
Result:
|
|
56
61
|
|
|
57
62
|
```
|
|
58
|
-
/projects/myrepo
|
|
63
|
+
/projects/myrepo/ ← new hub
|
|
59
64
|
├── .bare/
|
|
60
65
|
├── .git
|
|
61
66
|
├── main/
|
|
67
|
+
└── feature-x/
|
|
68
|
+
|
|
69
|
+
/projects/myrepo.old/ ← original repo (renamed)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The `.old` directory is kept so you can verify the migration before deleting it manually.
|
|
73
|
+
|
|
74
|
+
### Migration to a new location
|
|
75
|
+
|
|
76
|
+
When a destination is provided, the source repo is moved into the new hub as the main branch worktree:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
git-worktree-organize /projects/myrepo /projects/myrepo-hub
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Result:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
/projects/myrepo-hub/
|
|
86
|
+
├── .bare/
|
|
87
|
+
├── .git
|
|
88
|
+
├── main/ ← original /projects/myrepo moved here
|
|
62
89
|
├── feature-x/
|
|
63
90
|
└── hotfix/
|
|
64
91
|
```
|
|
65
92
|
|
|
66
|
-
The original
|
|
93
|
+
The original source directory becomes the `main/` worktree. No data is lost.
|
|
94
|
+
|
|
95
|
+
## Supported repository types
|
|
96
|
+
|
|
97
|
+
The tool detects and migrates five different git repository layouts:
|
|
98
|
+
|
|
99
|
+
| Type | Description |
|
|
100
|
+
|------|-------------|
|
|
101
|
+
| **Standard** | Ordinary repo with a `.git` directory |
|
|
102
|
+
| **Bare root** | Bare repo with git internals at the root (`HEAD`, `refs/`, `objects/`) |
|
|
103
|
+
| **Bare dotgit** | Repo where `.git` is a bare directory (`core.bare = true`) |
|
|
104
|
+
| **Bare external** | Repo where `.git` is a file pointing to a gitdir elsewhere |
|
|
105
|
+
| **Bare hub** | Already in the bare-hub layout (re-organizes worktrees into canonical structure) |
|
|
106
|
+
|
|
107
|
+
See [Layout conversions](#layout-conversions) for detailed before/after diagrams of each type.
|
|
108
|
+
|
|
109
|
+
## Recovery
|
|
110
|
+
|
|
111
|
+
Running the tool on an existing hub detects problems and offers to fix them:
|
|
112
|
+
|
|
113
|
+
- **Partial migrations** -- Resumes moving worktrees that weren't fully processed (e.g. after an interruption).
|
|
114
|
+
- **Stale `.git` pointers** -- Repairs worktrees with broken connections to the bare repo.
|
|
115
|
+
- **Missing worktrees** -- Searches for worktrees that were moved outside the hub (up to 3 directory levels deep).
|
|
116
|
+
- **Parent directory renames** -- Detects and repairs when a hub's parent directory was renamed.
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
# Resume a partial migration or repair an existing hub
|
|
120
|
+
git-worktree-organize /path/to/hub
|
|
121
|
+
|
|
122
|
+
# Repair after renaming a parent directory (can point to any worktree inside the hub)
|
|
123
|
+
git-worktree-organize /new/path/to/hub/some-worktree
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Safety
|
|
127
|
+
|
|
128
|
+
- **Interactive confirmation** -- Preview all changes before execution
|
|
129
|
+
- **Branch name sanitization** -- Slashes become hyphens (e.g. `feature/auth` becomes `feature-auth`)
|
|
130
|
+
- **Collision detection** -- Warns if sanitized names would conflict
|
|
131
|
+
- **AI agent documentation** -- Creates an `AGENTS.md` at the hub root for AI coding agents (never overwrites existing files)
|
|
132
|
+
- **Zero runtime dependencies** -- Only requires Node.js and git
|
|
133
|
+
|
|
134
|
+
## Why this layout?
|
|
135
|
+
|
|
136
|
+
Every branch as a sibling directory means you can work on multiple branches simultaneously. Run branch-specific builds side by side. No stashing, no context switching.
|
|
137
|
+
|
|
138
|
+
The `.git` file at the hub root is the key detail. Because it points to `.bare/`, git resolves the repository from any location in the tree:
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
# All of these work -- no -C flag or cd needed:
|
|
142
|
+
~/projects/myrepo $ git worktree list
|
|
143
|
+
~/projects/myrepo/main $ git worktree list
|
|
144
|
+
~/projects/myrepo/feature-x $ git worktree list
|
|
145
|
+
~/projects/myrepo/main/src/deep/nested $ git worktree list
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
IDEs, linters, pre-commit hooks, and AI coding agents all discover the repo automatically regardless of which worktree directory they're opened in.
|
|
67
149
|
|
|
68
|
-
##
|
|
150
|
+
## Requirements
|
|
69
151
|
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
- **Bare-dotgit** — repo where `.git` is a bare git directory (`core.bare = true`)
|
|
73
|
-
- **Bare-external** — repo where `.git` is a file pointing to a gitdir elsewhere
|
|
74
|
-
- **Bare-hub** — already in the bare-hub layout (re-organizes worktrees into the canonical structure)
|
|
152
|
+
- Node.js 18+
|
|
153
|
+
- Git 2.5+ (for worktree support)
|
|
75
154
|
|
|
76
|
-
|
|
155
|
+
## Development
|
|
77
156
|
|
|
78
|
-
|
|
157
|
+
```sh
|
|
158
|
+
git clone https://github.com/drmikecrowe/git-worktree-organize.git
|
|
159
|
+
cd git-worktree-organize
|
|
160
|
+
npm install
|
|
161
|
+
|
|
162
|
+
npm test # Run tests
|
|
163
|
+
npm run build # Build
|
|
164
|
+
node dist/cli.js /path/to/test/repo # Test locally
|
|
165
|
+
```
|
|
79
166
|
|
|
80
|
-
|
|
167
|
+
## Layout conversions
|
|
168
|
+
|
|
169
|
+
Detailed before/after diagrams for each supported repository type.
|
|
170
|
+
|
|
171
|
+
### Standard repository
|
|
172
|
+
|
|
173
|
+
The most common case -- a normal repo with a `.git` directory and optionally some linked worktrees.
|
|
174
|
+
|
|
175
|
+
**Before:**
|
|
176
|
+
```
|
|
177
|
+
myrepo/
|
|
178
|
+
├── .git/ ← standard git directory
|
|
179
|
+
├── src/
|
|
180
|
+
└── package.json
|
|
181
|
+
|
|
182
|
+
myrepo-feature/ ← linked worktree (created by git worktree add)
|
|
183
|
+
├── .git ← file pointing back to myrepo/.git/worktrees/feature
|
|
184
|
+
├── src/
|
|
185
|
+
└── package.json
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**After:**
|
|
189
|
+
```
|
|
190
|
+
myrepo/
|
|
191
|
+
├── .bare/ ← bare git repo (contents of old .git/)
|
|
192
|
+
├── .git ← file: "gitdir: ./.bare"
|
|
193
|
+
├── AGENTS.md
|
|
194
|
+
├── main/ ← main branch worktree (was myrepo/)
|
|
195
|
+
│ ├── src/
|
|
196
|
+
│ └── package.json
|
|
197
|
+
└── feature/ ← feature worktree (was myrepo-feature/)
|
|
198
|
+
├── .git ← file pointing to .bare/worktrees/feature
|
|
199
|
+
├── src/
|
|
200
|
+
└── package.json
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Bare root
|
|
204
|
+
|
|
205
|
+
A bare repository where git internals sit directly at the root. Often created by `git clone --bare` or `git init --bare`.
|
|
206
|
+
|
|
207
|
+
**Before:**
|
|
208
|
+
```
|
|
209
|
+
myrepo.git/
|
|
210
|
+
├── HEAD
|
|
211
|
+
├── config
|
|
212
|
+
├── objects/
|
|
213
|
+
└── refs/
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**After:**
|
|
217
|
+
```
|
|
218
|
+
myrepo-hub/
|
|
219
|
+
├── .bare/ ← git internals moved here
|
|
220
|
+
│ ├── HEAD
|
|
221
|
+
│ ├── config
|
|
222
|
+
│ ├── objects/
|
|
223
|
+
│ └── refs/
|
|
224
|
+
├── .git ← file: "gitdir: ./.bare"
|
|
225
|
+
└── AGENTS.md
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
No worktrees are created since a bare repo has no checked-out branches. Use `git worktree add <branch>` from the hub to start working.
|
|
229
|
+
|
|
230
|
+
### Bare dotgit
|
|
231
|
+
|
|
232
|
+
A repository where `.git` is a directory but `core.bare = true`.
|
|
233
|
+
|
|
234
|
+
**Before:**
|
|
235
|
+
```
|
|
236
|
+
myrepo/
|
|
237
|
+
└── .git/ ← directory, but core.bare = true
|
|
238
|
+
├── HEAD
|
|
239
|
+
├── config ← contains core.bare = true
|
|
240
|
+
├── objects/
|
|
241
|
+
└── refs/
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**After:**
|
|
245
|
+
```
|
|
246
|
+
myrepo-hub/
|
|
247
|
+
├── .bare/ ← contents of old .git/
|
|
248
|
+
├── .git ← file: "gitdir: ./.bare"
|
|
249
|
+
└── AGENTS.md
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Bare external
|
|
253
|
+
|
|
254
|
+
A repository where `.git` is a file pointing to a gitdir stored elsewhere on the filesystem.
|
|
255
|
+
|
|
256
|
+
**Before:**
|
|
257
|
+
```
|
|
258
|
+
myrepo/
|
|
259
|
+
├── .git ← file: "gitdir: /somewhere/else/myrepo.git"
|
|
260
|
+
├── src/
|
|
261
|
+
└── package.json
|
|
262
|
+
|
|
263
|
+
/somewhere/else/myrepo.git/
|
|
264
|
+
├── HEAD
|
|
265
|
+
├── objects/
|
|
266
|
+
└── refs/
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
**After:**
|
|
270
|
+
```
|
|
271
|
+
myrepo-hub/
|
|
272
|
+
├── .bare/ ← copy of /somewhere/else/myrepo.git/
|
|
273
|
+
├── .git ← file: "gitdir: ./.bare"
|
|
274
|
+
└── AGENTS.md
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Bare hub (re-organize)
|
|
278
|
+
|
|
279
|
+
Already in the bare-hub layout but with worktrees scattered in non-standard locations.
|
|
280
|
+
|
|
281
|
+
**Before:**
|
|
282
|
+
```
|
|
283
|
+
myrepo/
|
|
284
|
+
├── .bare/
|
|
285
|
+
├── .git ← file: "gitdir: ./.bare"
|
|
286
|
+
└── main/
|
|
287
|
+
|
|
288
|
+
/other/path/feature/ ← worktree outside the hub
|
|
289
|
+
└── .git
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
**After:**
|
|
293
|
+
```
|
|
294
|
+
myrepo/
|
|
295
|
+
├── .bare/
|
|
296
|
+
├── .git ← file: "gitdir: ./.bare"
|
|
297
|
+
├── AGENTS.md
|
|
298
|
+
├── main/
|
|
299
|
+
└── feature/ ← moved into the hub
|
|
300
|
+
└── .git ← repaired to point to .bare/worktrees/feature
|
|
301
|
+
```
|
|
81
302
|
|
|
82
303
|
## License
|
|
83
304
|
|
|
84
|
-
MIT
|
|
305
|
+
MIT -- see [github.com/drmikecrowe/git-worktree-organize](https://github.com/drmikecrowe/git-worktree-organize).
|