@gw-tools/gw 0.20.11 → 0.20.12-beta.2
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 +120 -164
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ A command-line tool for managing git worktrees, built with Deno.
|
|
|
22
22
|
- [Example Configuration](#example-configuration)
|
|
23
23
|
- [Configuration Options](#configuration-options)
|
|
24
24
|
- [Commands](#commands)
|
|
25
|
-
- [add](#
|
|
25
|
+
- [checkout (add, co)](#checkout)
|
|
26
26
|
- [Arguments](#arguments)
|
|
27
27
|
- [Options](#options)
|
|
28
28
|
- [Examples](#examples)
|
|
@@ -32,10 +32,6 @@ A command-line tool for managing git worktrees, built with Deno.
|
|
|
32
32
|
- [Arguments](#arguments-1)
|
|
33
33
|
- [Examples](#examples-1)
|
|
34
34
|
- [How It Works](#how-it-works)
|
|
35
|
-
- [checkout](#checkout)
|
|
36
|
-
- [Arguments](#arguments-2)
|
|
37
|
-
- [Examples](#examples-2)
|
|
38
|
-
- [How It Works](#how-it-works-1)
|
|
39
35
|
- [pr](#pr)
|
|
40
36
|
- [Arguments](#arguments-3)
|
|
41
37
|
- [Options](#options-1)
|
|
@@ -124,7 +120,7 @@ gw cd feat/new-feature
|
|
|
124
120
|
|
|
125
121
|
```bash
|
|
126
122
|
# Configure gw in an existing repository
|
|
127
|
-
gw init --auto-copy-files .env,secrets/ --post-
|
|
123
|
+
gw init --auto-copy-files .env,secrets/ --post-checkout "pnpm install"
|
|
128
124
|
|
|
129
125
|
# Create worktrees - files are copied automatically, dependencies installed
|
|
130
126
|
gw add feat/another-feature
|
|
@@ -165,7 +161,7 @@ Once installed, your AI agent can:
|
|
|
165
161
|
|
|
166
162
|
## Initial Setup: Secrets in the Default Branch
|
|
167
163
|
|
|
168
|
-
**Important:** Before using `gw
|
|
164
|
+
**Important:** Before using `gw checkout` with auto-copy, ensure your secrets and environment files exist in your `defaultBranch` worktree (typically `main`). This worktree is the **source** from which files are copied to new worktrees.
|
|
169
165
|
|
|
170
166
|
### First-Time Setup Flow
|
|
171
167
|
|
|
@@ -203,7 +199,7 @@ gw add feat/new-feature
|
|
|
203
199
|
# Clone with configuration in one command
|
|
204
200
|
gw init git@github.com:user/repo.git \
|
|
205
201
|
--auto-copy-files .env,secrets/ \
|
|
206
|
-
--post-
|
|
202
|
+
--post-checkout "pnpm install"
|
|
207
203
|
|
|
208
204
|
# Then set up secrets in main worktree as shown above
|
|
209
205
|
cd repo.git/main
|
|
@@ -213,7 +209,7 @@ cp .env.example .env
|
|
|
213
209
|
|
|
214
210
|
### Why This Matters
|
|
215
211
|
|
|
216
|
-
- **`gw
|
|
212
|
+
- **`gw checkout`** copies files **from** your `defaultBranch` worktree **to** the new worktree
|
|
217
213
|
- **`gw sync`** also uses `defaultBranch` as the source (unless `--from` is specified)
|
|
218
214
|
- **Auto-clean** will **never** remove the `defaultBranch` worktree, ensuring your source files are always available
|
|
219
215
|
- If secrets don't exist in `defaultBranch`, they won't be copied to new worktrees
|
|
@@ -313,7 +309,7 @@ gw init --root /path/to/your/repo.git
|
|
|
313
309
|
// Auto-copy these files when creating new worktrees
|
|
314
310
|
"autoCopyFiles": [".env", "components/agents/.env", "components/ui/.vercel/"],
|
|
315
311
|
"hooks": {
|
|
316
|
-
"
|
|
312
|
+
"checkout": {
|
|
317
313
|
"pre": ["echo 'Creating worktree: {worktree}'"],
|
|
318
314
|
"post": ["pnpm install", "echo 'Setup complete!'"],
|
|
319
315
|
},
|
|
@@ -333,33 +329,46 @@ gw init --root /path/to/your/repo.git
|
|
|
333
329
|
|
|
334
330
|
- **root**: Absolute path to the git repository root (automatically detected or manually set with `gw init`)
|
|
335
331
|
- **defaultBranch**: Default source worktree name (optional, defaults to "main")
|
|
336
|
-
- **autoCopyFiles**: Array of file/directory paths to automatically copy when creating worktrees with `gw
|
|
337
|
-
- **hooks**: Command hooks configuration (optional, set via `gw init --pre-
|
|
338
|
-
- **hooks.
|
|
339
|
-
- **hooks.
|
|
332
|
+
- **autoCopyFiles**: Array of file/directory paths to automatically copy when creating worktrees with `gw checkout` (optional, only set via `gw init --auto-copy-files`)
|
|
333
|
+
- **hooks**: Command hooks configuration (optional, set via `gw init --pre-checkout` and `--post-checkout`)
|
|
334
|
+
- **hooks.checkout.pre**: Array of commands to run before creating a worktree
|
|
335
|
+
- **hooks.checkout.post**: Array of commands to run after creating a worktree
|
|
340
336
|
- **cleanThreshold**: Number of days before worktrees are considered stale for `gw clean` (optional, defaults to 7, set via `gw init --clean-threshold`)
|
|
341
|
-
- **autoClean**: Prompt to remove stale worktrees when running `gw
|
|
337
|
+
- **autoClean**: Prompt to remove stale worktrees when running `gw checkout` or `gw list` (optional, defaults to false, set via `gw init --auto-clean`)
|
|
342
338
|
- **updateStrategy**: Default strategy for `gw update` command: "merge" or "rebase" (optional, defaults to "merge", set via `gw init --update-strategy`)
|
|
343
339
|
- **lastAutoCleanTime**: Internal timestamp tracking last auto-cleanup run (managed automatically, do not edit manually)
|
|
344
340
|
|
|
345
341
|
## Commands
|
|
346
342
|
|
|
347
|
-
###
|
|
343
|
+
### checkout
|
|
344
|
+
|
|
345
|
+
Create a new git worktree, switch to an existing branch, or navigate to a worktree where a branch is checked out. This is the primary command for working with branches in a worktree workflow.
|
|
348
346
|
|
|
349
|
-
|
|
347
|
+
**Aliases:** `co`, `add` (for backwards compatibility)
|
|
350
348
|
|
|
351
349
|
```bash
|
|
352
|
-
gw
|
|
350
|
+
gw checkout <branch-name> [files...]
|
|
351
|
+
# or use aliases
|
|
352
|
+
gw co <branch-name>
|
|
353
|
+
gw add <branch-name> # backwards-compatible alias
|
|
353
354
|
```
|
|
354
355
|
|
|
355
|
-
This command
|
|
356
|
+
This unified command handles all branch operations in a worktree workflow:
|
|
357
|
+
|
|
358
|
+
1. **Branch exists locally, not checked out:** Creates a worktree for it
|
|
359
|
+
2. **Branch is checked out in another worktree:** Navigates to that worktree
|
|
360
|
+
3. **Branch exists on remote only:** Prompts to create a worktree for it
|
|
361
|
+
4. **Branch doesn't exist:** Creates a new branch from the default branch and a worktree for it
|
|
362
|
+
5. **Already on the branch:** Shows "Already on branch" message
|
|
363
|
+
|
|
364
|
+
If `autoCopyFiles` is configured, those files are automatically copied when creating new worktrees. You can override this by specifying files as arguments.
|
|
356
365
|
|
|
357
366
|
**Branch Creation Behavior:**
|
|
358
|
-
When creating a new worktree without specifying an existing branch, `gw
|
|
367
|
+
When creating a new worktree without specifying an existing branch, `gw checkout` automatically fetches the latest version of your default branch (e.g., `main`) from the remote (e.g., `origin/main`) to ensure your new branch is based on the most recent code. You can override this with the `--from <branch>` option to create a branch from a different source branch instead.
|
|
359
368
|
|
|
360
369
|
**Remote-First Fetch Approach:**
|
|
361
370
|
|
|
362
|
-
The `gw
|
|
371
|
+
The `gw checkout` command follows a remote-first approach when creating new branches:
|
|
363
372
|
|
|
364
373
|
1. **What happens**: When you create a new branch (e.g., `gw add feat/new-feature`), the command:
|
|
365
374
|
- Fetches the latest version of the source branch from the remote (e.g., `origin/main`)
|
|
@@ -383,7 +392,7 @@ The `gw add` command follows a remote-first approach when creating new branches:
|
|
|
383
392
|
- When no `--from` is specified (using default branch) or when no remote is configured, the command will warn about fetch failures but allow creation using the local branch.
|
|
384
393
|
|
|
385
394
|
**Upstream Tracking:**
|
|
386
|
-
When `gw
|
|
395
|
+
When `gw checkout` creates a new branch, it automatically configures the branch to track `origin/<branch-name>` (e.g., `origin/feat/my-feature`). This means `git push` will push to the correct remote branch without needing to specify `-u origin <branch>` on first push.
|
|
387
396
|
|
|
388
397
|
**Git Ref Conflict Detection:**
|
|
389
398
|
The command automatically detects and prevents Git ref naming conflicts. For example, you cannot have both a branch named `test` and `test/foo` because Git stores branches as files in `.git/refs/heads/`, and `test` cannot be both a file and a directory. If a conflict is detected, you'll receive a helpful error message with suggestions for resolving it.
|
|
@@ -396,7 +405,7 @@ If you try to add a worktree that already exists, the command will prompt you to
|
|
|
396
405
|
|
|
397
406
|
#### Arguments
|
|
398
407
|
|
|
399
|
-
- `<
|
|
408
|
+
- `<branch-name>`: Branch name to checkout or create
|
|
400
409
|
- `[files...]`: Optional files to copy (overrides `autoCopyFiles` config)
|
|
401
410
|
|
|
402
411
|
#### Options
|
|
@@ -416,35 +425,46 @@ All `git worktree add` options are supported:
|
|
|
416
425
|
#### Examples
|
|
417
426
|
|
|
418
427
|
```bash
|
|
419
|
-
# Create worktree (auto-copies files if autoCopyFiles is configured)
|
|
428
|
+
# Create worktree for new branch (auto-copies files if autoCopyFiles is configured)
|
|
420
429
|
# Automatically navigates to new worktree
|
|
421
|
-
gw
|
|
430
|
+
gw checkout feat/new-feature
|
|
431
|
+
gw co feat/new-feature # Using alias
|
|
432
|
+
|
|
433
|
+
# Navigate to worktree where main is already checked out
|
|
434
|
+
gw checkout main
|
|
435
|
+
# Output: Branch main is checked out in another worktree:
|
|
436
|
+
# /path/to/repo/main
|
|
437
|
+
#
|
|
438
|
+
# Navigating there...
|
|
422
439
|
|
|
423
440
|
# Create worktree without navigating to it
|
|
424
|
-
gw
|
|
441
|
+
gw checkout feat/new-feature --no-cd
|
|
425
442
|
|
|
426
443
|
# Create worktree from a different branch instead of defaultBranch
|
|
427
|
-
gw
|
|
444
|
+
gw checkout feat/new-feature --from develop
|
|
428
445
|
|
|
429
446
|
# Create child feature branch from parent feature branch
|
|
430
|
-
gw
|
|
447
|
+
gw checkout feat/child-feature --from feat/parent-feature
|
|
431
448
|
|
|
432
449
|
# Create worktree with new branch
|
|
433
|
-
gw
|
|
450
|
+
gw checkout feat/new-feature -b my-branch
|
|
434
451
|
|
|
435
452
|
# Create worktree and copy specific files (overrides config)
|
|
436
|
-
gw
|
|
453
|
+
gw checkout feat/new-feature .env secrets/
|
|
437
454
|
|
|
438
455
|
# Force create even if branch exists elsewhere
|
|
439
|
-
gw
|
|
456
|
+
gw checkout feat/bugfix -f
|
|
440
457
|
|
|
441
|
-
#
|
|
442
|
-
gw
|
|
443
|
-
# Output:
|
|
444
|
-
# /path/to/repo/feat/existing-branch
|
|
458
|
+
# Create worktree for remote branch (prompts)
|
|
459
|
+
gw checkout remote-feature
|
|
460
|
+
# Output: Branch remote-feature exists on remote but not locally.
|
|
445
461
|
#
|
|
446
|
-
#
|
|
447
|
-
# (
|
|
462
|
+
# Create a new worktree for it? [Y/n]:
|
|
463
|
+
# (If yes, creates the worktree)
|
|
464
|
+
|
|
465
|
+
# Already on the branch
|
|
466
|
+
gw checkout current-branch
|
|
467
|
+
# Output: Already on 'current-branch'
|
|
448
468
|
```
|
|
449
469
|
|
|
450
470
|
#### Auto-Copy Configuration
|
|
@@ -465,21 +485,21 @@ This creates:
|
|
|
465
485
|
}
|
|
466
486
|
```
|
|
467
487
|
|
|
468
|
-
Now every time you run `gw
|
|
488
|
+
Now every time you run `gw checkout`, these files will be automatically copied from your default source worktree (usually `main`) to the new worktree.
|
|
469
489
|
|
|
470
490
|
#### Hooks
|
|
471
491
|
|
|
472
|
-
You can configure pre-
|
|
492
|
+
You can configure pre-checkout and post-checkout hooks to run commands before and after worktree creation. This is useful for:
|
|
473
493
|
|
|
474
|
-
- **Pre-
|
|
475
|
-
- **Post-
|
|
494
|
+
- **Pre-checkout hooks**: Running validation scripts, checking prerequisites
|
|
495
|
+
- **Post-checkout hooks**: Installing dependencies, setting up the environment
|
|
476
496
|
|
|
477
497
|
```bash
|
|
478
|
-
# Configure a post-
|
|
479
|
-
gw init --post-
|
|
498
|
+
# Configure a post-checkout hook to install dependencies
|
|
499
|
+
gw init --post-checkout "pnpm install"
|
|
480
500
|
|
|
481
501
|
# Configure multiple hooks
|
|
482
|
-
gw init --pre-
|
|
502
|
+
gw init --pre-checkout "echo 'Creating: {worktree}'" --post-checkout "pnpm install" --post-checkout "echo 'Done!'"
|
|
483
503
|
```
|
|
484
504
|
|
|
485
505
|
**Hook Variables:**
|
|
@@ -493,17 +513,17 @@ Hooks support variable substitution:
|
|
|
493
513
|
|
|
494
514
|
**Hook Behavior:**
|
|
495
515
|
|
|
496
|
-
- **Pre-
|
|
497
|
-
- **Post-
|
|
516
|
+
- **Pre-checkout hooks** run before the worktree is created (in the git root directory). If any pre-checkout hook fails, the worktree creation is aborted.
|
|
517
|
+
- **Post-checkout hooks** run after the worktree is created and files are copied (in the new worktree directory). If a post-checkout hook fails, a warning is shown but the worktree creation is considered successful.
|
|
498
518
|
|
|
499
519
|
**Example: Auto-install dependencies**
|
|
500
520
|
|
|
501
521
|
```bash
|
|
502
522
|
# One-time setup
|
|
503
|
-
gw init --auto-copy-files .env --post-
|
|
523
|
+
gw init --auto-copy-files .env --post-checkout "pnpm install"
|
|
504
524
|
|
|
505
525
|
# Now when you create a worktree:
|
|
506
|
-
gw
|
|
526
|
+
gw checkout feat/new-feature
|
|
507
527
|
# 1. Creates the worktree
|
|
508
528
|
# 2. Copies .env file
|
|
509
529
|
# 3. Runs pnpm install in the new worktree
|
|
@@ -547,79 +567,6 @@ The `cd` command integrates with your shell through an automatically installed f
|
|
|
547
567
|
|
|
548
568
|
**Note**: Shell integration is automatically installed when you install via npm. If needed, you can manually install or remove it using `gw install-shell`.
|
|
549
569
|
|
|
550
|
-
### checkout
|
|
551
|
-
|
|
552
|
-
Smart git checkout wrapper that provides an intuitive experience for working with worktrees. The command automatically handles scenarios that would normally cause errors with standard `git checkout`.
|
|
553
|
-
|
|
554
|
-
```bash
|
|
555
|
-
gw checkout <branch>
|
|
556
|
-
# or use the alias
|
|
557
|
-
gw co <branch>
|
|
558
|
-
```
|
|
559
|
-
|
|
560
|
-
When you're working with worktrees, you cannot checkout the same branch in multiple worktrees. The `gw checkout` command solves this by detecting when a branch is already checked out elsewhere and navigating you to that worktree instead of showing an error.
|
|
561
|
-
|
|
562
|
-
#### Arguments
|
|
563
|
-
|
|
564
|
-
- `<branch>`: Branch name to checkout
|
|
565
|
-
|
|
566
|
-
#### Examples
|
|
567
|
-
|
|
568
|
-
```bash
|
|
569
|
-
# Checkout a local branch (if not checked out elsewhere)
|
|
570
|
-
gw checkout feature-x
|
|
571
|
-
gw co feature-x # Using alias
|
|
572
|
-
|
|
573
|
-
# Navigate to worktree where main is already checked out
|
|
574
|
-
gw checkout main
|
|
575
|
-
# Output: Branch main is checked out in another worktree:
|
|
576
|
-
# /path/to/repo/main
|
|
577
|
-
#
|
|
578
|
-
# Navigating there...
|
|
579
|
-
|
|
580
|
-
# Create worktree for remote branch (prompts)
|
|
581
|
-
gw checkout remote-feature
|
|
582
|
-
# Output: Branch remote-feature exists on remote but not locally.
|
|
583
|
-
#
|
|
584
|
-
# Create a new worktree for it? [Y/n]:
|
|
585
|
-
# (If yes, runs: gw add remote-feature)
|
|
586
|
-
|
|
587
|
-
# Already on the branch
|
|
588
|
-
gw checkout current-branch
|
|
589
|
-
# Output: Already on 'current-branch'
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
#### How It Works
|
|
593
|
-
|
|
594
|
-
The `checkout` command intelligently handles four scenarios:
|
|
595
|
-
|
|
596
|
-
1. **Branch exists locally and isn't checked out anywhere:**
|
|
597
|
-
- Performs standard `git checkout <branch>` in the current worktree
|
|
598
|
-
|
|
599
|
-
2. **Branch is already checked out in another worktree:**
|
|
600
|
-
- Automatically navigates to that worktree (like `gw cd`)
|
|
601
|
-
- Shows you where the branch is located
|
|
602
|
-
|
|
603
|
-
3. **Branch exists on remote but not locally:**
|
|
604
|
-
- Prompts you to create a new worktree for it
|
|
605
|
-
- If you confirm, runs `gw add <branch>` which:
|
|
606
|
-
- Creates the worktree
|
|
607
|
-
- Copies auto-copy files
|
|
608
|
-
- Navigates to the new worktree
|
|
609
|
-
|
|
610
|
-
4. **Branch doesn't exist anywhere:**
|
|
611
|
-
- Shows a helpful error message
|
|
612
|
-
- Suggests using `gw add <branch>` to create a new branch
|
|
613
|
-
|
|
614
|
-
**Why use this instead of `git checkout`?**
|
|
615
|
-
|
|
616
|
-
- **No more confusing errors:** Instead of "fatal: 'main' is already checked out at '/path/to/main'", it just takes you there
|
|
617
|
-
- **Reduces mental overhead:** You don't need to remember which branches are where
|
|
618
|
-
- **Teaches worktree workflows:** The messages guide you toward the right action
|
|
619
|
-
- **Educational:** Prompts explain what's happening and suggest alternatives
|
|
620
|
-
|
|
621
|
-
**Use case:** When updating your feature branch with latest changes, you might instinctively try `git checkout main && git pull`. With worktrees, this fails because main is checked out elsewhere. Instead, use `gw update` to update your current branch with main, or use `gw checkout main` to navigate to the main worktree.
|
|
622
|
-
|
|
623
570
|
### pr
|
|
624
571
|
|
|
625
572
|
Check out a pull request into a new worktree. This command fetches a PR's branch and creates a worktree for it in one step, making it easy to review, test, or contribute to pull requests.
|
|
@@ -676,8 +623,8 @@ gw pr 42 --no-cd
|
|
|
676
623
|
3. **Checks for existing worktree**: If the branch is already checked out, offers to navigate there
|
|
677
624
|
4. **Fetches PR branch**: Uses `git fetch origin pull/<number>/head:<branch>` pattern which works for both same-repo and fork PRs
|
|
678
625
|
5. **Creates worktree**: Creates a new worktree with the PR's branch
|
|
679
|
-
6. **Copies files**: Auto-copies files from `autoCopyFiles` config (same as `gw
|
|
680
|
-
7. **Runs hooks**: Executes pre-
|
|
626
|
+
6. **Copies files**: Auto-copies files from `autoCopyFiles` config (same as `gw checkout`)
|
|
627
|
+
7. **Runs hooks**: Executes pre-checkout and post-checkout hooks (same as `gw checkout`)
|
|
681
628
|
8. **Navigates**: Automatically navigates to the new worktree
|
|
682
629
|
|
|
683
630
|
**Fork Handling:**
|
|
@@ -786,7 +733,7 @@ Shell integration provides:
|
|
|
786
733
|
|
|
787
734
|
- **Navigation support**: `gw cd <worktree>` navigates directly to worktrees
|
|
788
735
|
- **Real-time streaming**: Command output streams as it's generated (no buffering)
|
|
789
|
-
- **Auto-navigation**: Automatically navigate after `gw
|
|
736
|
+
- **Auto-navigation**: Automatically navigate after `gw checkout` and `gw remove` operations
|
|
790
737
|
- **Multi-alias support**: Install for different command names (e.g., `gw-dev` for development)
|
|
791
738
|
|
|
792
739
|
```bash
|
|
@@ -884,11 +831,11 @@ gw init [repository-url] [directory] [options]
|
|
|
884
831
|
- `-i, --interactive`: Interactively prompt for configuration options
|
|
885
832
|
- `--root <path>`: Specify the git repository root path (optional, auto-detects if not provided)
|
|
886
833
|
- `--default-source <name>`: Set the default source worktree (default: "main")
|
|
887
|
-
- `--auto-copy-files <files>`: Comma-separated list of files to auto-copy when creating worktrees with `gw
|
|
888
|
-
- `--pre-
|
|
889
|
-
- `--post-
|
|
834
|
+
- `--auto-copy-files <files>`: Comma-separated list of files to auto-copy when creating worktrees with `gw checkout`
|
|
835
|
+
- `--pre-checkout <command>`: Command to run before `gw checkout` creates a worktree (can be specified multiple times)
|
|
836
|
+
- `--post-checkout <command>`: Command to run after `gw checkout` creates a worktree (can be specified multiple times)
|
|
890
837
|
- `--clean-threshold <days>`: Number of days before worktrees are considered stale for `gw clean` (default: 7)
|
|
891
|
-
- `--auto-clean`: Enable automatic cleanup of stale worktrees (runs on `gw
|
|
838
|
+
- `--auto-clean`: Enable automatic cleanup of stale worktrees (runs on `gw checkout` and `gw list` with 24-hour cooldown)
|
|
892
839
|
- `--update-strategy <strategy>`: Set default update strategy: 'merge' or 'rebase' (default: merge)
|
|
893
840
|
- `-h, --help`: Show help message
|
|
894
841
|
|
|
@@ -901,7 +848,7 @@ Clone a repository and automatically set it up with gw configuration. **This is
|
|
|
901
848
|
gw init git@github.com:user/repo.git --interactive
|
|
902
849
|
# Prompts for:
|
|
903
850
|
# - Auto-copy files (.env, secrets/, etc.)
|
|
904
|
-
# - Pre-
|
|
851
|
+
# - Pre-checkout and post-checkout hooks (pnpm install, etc.)
|
|
905
852
|
# - Clean threshold
|
|
906
853
|
# - Update strategy
|
|
907
854
|
# Then automatically creates the main worktree and navigates to the repo
|
|
@@ -909,7 +856,7 @@ gw init git@github.com:user/repo.git --interactive
|
|
|
909
856
|
# Clone with configuration in one command (non-interactive)
|
|
910
857
|
gw init git@github.com:user/repo.git \
|
|
911
858
|
--auto-copy-files .env,secrets/ \
|
|
912
|
-
--post-
|
|
859
|
+
--post-checkout "pnpm install"
|
|
913
860
|
|
|
914
861
|
# Clone into specific directory
|
|
915
862
|
gw init git@github.com:user/repo.git my-project --interactive
|
|
@@ -934,7 +881,7 @@ gw init git@github.com:user/repo.git
|
|
|
934
881
|
|
|
935
882
|
- No need to manually run `git clone --bare` or `git worktree add`
|
|
936
883
|
- Configuration is set up immediately
|
|
937
|
-
- Ready to use `gw
|
|
884
|
+
- Ready to use `gw checkout` right away
|
|
938
885
|
|
|
939
886
|
**Notes:**
|
|
940
887
|
|
|
@@ -958,13 +905,13 @@ gw init
|
|
|
958
905
|
gw init --auto-copy-files .env,secrets/
|
|
959
906
|
|
|
960
907
|
# Initialize with post-add hook to install dependencies
|
|
961
|
-
gw init --post-
|
|
908
|
+
gw init --post-checkout "pnpm install"
|
|
962
909
|
|
|
963
910
|
# Initialize with pre-add validation hook
|
|
964
|
-
gw init --pre-
|
|
911
|
+
gw init --pre-checkout "echo 'Creating worktree: {worktree}'"
|
|
965
912
|
|
|
966
913
|
# Initialize with multiple hooks
|
|
967
|
-
gw init --pre-
|
|
914
|
+
gw init --pre-checkout "echo 'Starting...'" --post-checkout "pnpm install" --post-checkout "echo 'Done!'"
|
|
968
915
|
|
|
969
916
|
# Initialize with custom default source
|
|
970
917
|
gw init --default-source master
|
|
@@ -979,7 +926,7 @@ gw init --clean-threshold 14
|
|
|
979
926
|
gw init --update-strategy rebase
|
|
980
927
|
|
|
981
928
|
# Full configuration example
|
|
982
|
-
gw init --auto-copy-files .env,secrets/ --post-
|
|
929
|
+
gw init --auto-copy-files .env,secrets/ --post-checkout "pnpm install" --clean-threshold 14 --update-strategy merge
|
|
983
930
|
|
|
984
931
|
# Show help
|
|
985
932
|
gw init --help
|
|
@@ -1006,12 +953,12 @@ gw init --auto-clean
|
|
|
1006
953
|
gw init --auto-clean --clean-threshold 14
|
|
1007
954
|
|
|
1008
955
|
# Enable with other options
|
|
1009
|
-
gw init --auto-clean --auto-copy-files .env --post-
|
|
956
|
+
gw init --auto-clean --auto-copy-files .env --post-checkout "pnpm install"
|
|
1010
957
|
```
|
|
1011
958
|
|
|
1012
959
|
**How it works:**
|
|
1013
960
|
|
|
1014
|
-
- Prompts after `gw
|
|
961
|
+
- Prompts after `gw checkout` and `gw list` commands when stale worktrees are detected
|
|
1015
962
|
- Only prompts once per 24 hours (cooldown)
|
|
1016
963
|
- **Never removes the `defaultBranch` worktree** - it's protected as the source for file syncing
|
|
1017
964
|
- Checks for worktrees older than `cleanThreshold` with:
|
|
@@ -1081,7 +1028,7 @@ If your `.gw/config.json` contains:
|
|
|
1081
1028
|
"defaultBranch": "main",
|
|
1082
1029
|
"autoCopyFiles": [".env", "secrets/"],
|
|
1083
1030
|
"hooks": {
|
|
1084
|
-
"
|
|
1031
|
+
"checkout": {
|
|
1085
1032
|
"post": ["pnpm install"]
|
|
1086
1033
|
}
|
|
1087
1034
|
},
|
|
@@ -1093,7 +1040,7 @@ If your `.gw/config.json` contains:
|
|
|
1093
1040
|
Then `gw show-init` will output:
|
|
1094
1041
|
|
|
1095
1042
|
```bash
|
|
1096
|
-
gw init --root /Users/username/Workspace/repo.git --auto-copy-files .env,secrets/ --post-
|
|
1043
|
+
gw init --root /Users/username/Workspace/repo.git --auto-copy-files .env,secrets/ --post-checkout 'pnpm install' --update-strategy rebase
|
|
1097
1044
|
```
|
|
1098
1045
|
|
|
1099
1046
|
#### When to Use
|
|
@@ -1110,12 +1057,12 @@ Use `gw show-init` to:
|
|
|
1110
1057
|
Sync files and directories between worktrees, preserving directory structure.
|
|
1111
1058
|
|
|
1112
1059
|
```bash
|
|
1113
|
-
gw sync [options]
|
|
1060
|
+
gw sync [options] [target-worktree] [files...]
|
|
1114
1061
|
```
|
|
1115
1062
|
|
|
1116
1063
|
#### Arguments
|
|
1117
1064
|
|
|
1118
|
-
-
|
|
1065
|
+
- `[target-worktree]`: Name or full path of the target worktree. If omitted, defaults to the current worktree
|
|
1119
1066
|
- `[files...]`: One or more files or directories to sync (paths relative to worktree root). If omitted, uses `autoCopyFiles` from `.gw/config.json`
|
|
1120
1067
|
|
|
1121
1068
|
#### Options
|
|
@@ -1127,7 +1074,10 @@ gw sync [options] <target-worktree> [files...]
|
|
|
1127
1074
|
#### Examples
|
|
1128
1075
|
|
|
1129
1076
|
```bash
|
|
1130
|
-
# Sync autoCopyFiles
|
|
1077
|
+
# Sync autoCopyFiles to current worktree (if inside a worktree)
|
|
1078
|
+
gw sync
|
|
1079
|
+
|
|
1080
|
+
# Sync autoCopyFiles from config to a specific target
|
|
1131
1081
|
gw sync feat-branch
|
|
1132
1082
|
|
|
1133
1083
|
# Sync .env file from main to feat-branch
|
|
@@ -1205,7 +1155,8 @@ The clean command:
|
|
|
1205
1155
|
| `gw clean` | No (all worktrees) | Yes (unless --force) | Clean up all finished work |
|
|
1206
1156
|
| `gw clean --use-autoclean-threshold` | Yes (7+ days) | Yes (unless --force) | Clean up old, stale worktrees |
|
|
1207
1157
|
| `gw clean --force` | No (all worktrees) | No | Force removal of all worktrees |
|
|
1208
|
-
| `gw prune
|
|
1158
|
+
| `gw prune` | No (all worktrees) | Yes | Full cleanup (worktrees + branches) |
|
|
1159
|
+
| `gw prune --stale-only` | N/A | N/A | Git passthrough (metadata only) |
|
|
1209
1160
|
|
|
1210
1161
|
**Safety Features:**
|
|
1211
1162
|
|
|
@@ -1301,13 +1252,13 @@ gw mv feat-branch ../new-location
|
|
|
1301
1252
|
|
|
1302
1253
|
#### prune
|
|
1303
1254
|
|
|
1304
|
-
Clean up
|
|
1255
|
+
Clean up worktrees and orphan branches. By default, performs full cleanup (removes clean worktrees AND deletes orphan branches).
|
|
1305
1256
|
|
|
1306
|
-
**
|
|
1307
|
-
|
|
1257
|
+
**Default Mode (full cleanup):**
|
|
1258
|
+
Removes worktrees that are safe to delete (no uncommitted changes, no unpushed commits) AND deletes orphan branches (branches without associated worktrees).
|
|
1308
1259
|
|
|
1309
|
-
**
|
|
1310
|
-
|
|
1260
|
+
**Stale-Only Mode** (with `--stale-only`):
|
|
1261
|
+
Git passthrough - only cleans up administrative files for deleted worktrees. Does not remove worktrees or branches.
|
|
1311
1262
|
|
|
1312
1263
|
```bash
|
|
1313
1264
|
gw prune [options]
|
|
@@ -1315,42 +1266,47 @@ gw prune [options]
|
|
|
1315
1266
|
|
|
1316
1267
|
**Options:**
|
|
1317
1268
|
|
|
1318
|
-
- `--
|
|
1269
|
+
- `--stale-only` - Git passthrough mode (only metadata cleanup)
|
|
1270
|
+
- `--no-branches` - Skip orphan branch cleanup (worktrees only)
|
|
1319
1271
|
- `-n, --dry-run` - Preview what would be removed
|
|
1320
1272
|
- `-f, --force` - Skip confirmation prompt
|
|
1321
1273
|
- `-v, --verbose` - Show detailed output
|
|
1322
1274
|
- `-h, --help` - Show help
|
|
1323
1275
|
|
|
1324
|
-
**Safety Features
|
|
1276
|
+
**Safety Features:**
|
|
1325
1277
|
|
|
1326
1278
|
- Default branch is protected (configured in `.gw/config.json`)
|
|
1327
1279
|
- gw_root branch is protected (bare repository root)
|
|
1328
1280
|
- Current worktree cannot be removed
|
|
1329
1281
|
- Bare repository is never removed
|
|
1330
|
-
-
|
|
1282
|
+
- Branches with unpushed commits are protected
|
|
1283
|
+
- Confirmation prompt before removal (defaults to yes)
|
|
1331
1284
|
|
|
1332
1285
|
**Examples:**
|
|
1333
1286
|
|
|
1334
1287
|
```bash
|
|
1335
|
-
#
|
|
1336
|
-
gw prune
|
|
1337
|
-
gw prune --
|
|
1288
|
+
# Full cleanup (default) - removes worktrees AND orphan branches
|
|
1289
|
+
gw prune # Remove clean worktrees and orphan branches
|
|
1290
|
+
gw prune --dry-run # Preview what would be removed
|
|
1291
|
+
gw prune --force # Skip confirmation
|
|
1292
|
+
gw prune --verbose # Show detailed output
|
|
1293
|
+
|
|
1294
|
+
# Skip branch cleanup
|
|
1295
|
+
gw prune --no-branches # Only clean worktrees, keep branches
|
|
1338
1296
|
|
|
1339
|
-
#
|
|
1340
|
-
gw prune --
|
|
1341
|
-
gw prune --clean --dry-run # Preview what would be removed
|
|
1342
|
-
gw prune --clean --force # Remove without confirmation
|
|
1343
|
-
gw prune --clean --verbose # Show detailed output
|
|
1297
|
+
# Git passthrough (stale-only)
|
|
1298
|
+
gw prune --stale-only # Only clean git metadata (like git worktree prune)
|
|
1344
1299
|
```
|
|
1345
1300
|
|
|
1346
1301
|
**Comparison with `gw clean`:**
|
|
1347
|
-
| Feature | `gw clean` | `gw clean --use-autoclean-threshold` | `gw prune
|
|
1302
|
+
| Feature | `gw clean` | `gw clean --use-autoclean-threshold` | `gw prune` |
|
|
1348
1303
|
|---------|-----------|-------------------------------------|-------------------|
|
|
1349
1304
|
| Age-based | No (all worktrees) | Yes (configurable threshold) | No (removes all clean) |
|
|
1350
1305
|
| Safety checks | Yes | Yes | Yes |
|
|
1351
1306
|
| Protects default branch | No | No | Yes |
|
|
1307
|
+
| Deletes orphan branches | No | No | Yes |
|
|
1352
1308
|
| Runs `git worktree prune` | No | No | Yes |
|
|
1353
|
-
| Use case | Clean up finished work | Regular maintenance |
|
|
1309
|
+
| Use case | Clean up finished work | Regular maintenance | Full cleanup |
|
|
1354
1310
|
|
|
1355
1311
|
#### lock
|
|
1356
1312
|
|
|
@@ -1435,7 +1391,7 @@ gw cd feat/new-feature
|
|
|
1435
1391
|
```bash
|
|
1436
1392
|
# One-time setup: Configure auto-copy files and hooks
|
|
1437
1393
|
gw init --auto-copy-files .env,components/agents/.env,components/ui/.vercel/ \
|
|
1438
|
-
--post-
|
|
1394
|
+
--post-checkout "pnpm install"
|
|
1439
1395
|
|
|
1440
1396
|
# From within any worktree of your repository
|
|
1441
1397
|
# Create a new worktree with auto-copy and hooks
|
|
@@ -1658,7 +1614,7 @@ packages/gw-tool/
|
|
|
1658
1614
|
│ ├── main.ts # CLI entry point and command dispatcher
|
|
1659
1615
|
│ ├── index.ts # Public API exports
|
|
1660
1616
|
│ ├── commands/ # Command implementations
|
|
1661
|
-
│ │ ├──
|
|
1617
|
+
│ │ ├── checkout.ts # Checkout command (create worktree, switch branches, navigate)
|
|
1662
1618
|
│ │ ├── copy.ts # Sync command (sync files between worktrees)
|
|
1663
1619
|
│ │ ├── init.ts # Init command
|
|
1664
1620
|
│ │ ├── root.ts # Root command
|
|
@@ -1693,7 +1649,7 @@ packages/gw-tool/
|
|
|
1693
1649
|
|
|
1694
1650
|
There are two types of commands you can add:
|
|
1695
1651
|
|
|
1696
|
-
#### Custom Commands (like `
|
|
1652
|
+
#### Custom Commands (like `checkout`, `sync`)
|
|
1697
1653
|
|
|
1698
1654
|
For commands with custom logic, follow the pattern used by existing commands:
|
|
1699
1655
|
|