@gw-tools/gw 0.20.12 → 0.20.14

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.
Files changed (2) hide show
  1. package/README.md +115 -161
  2. 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](#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-add "pnpm install"
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 add` 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.
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-add "pnpm install"
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 add`** copies files **from** your `defaultBranch` worktree **to** the new worktree
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
- "add": {
312
+ "checkout": {
317
313
  "pre": ["echo 'Creating worktree: {worktree}'"],
318
314
  "post": ["pnpm install", "echo 'Setup complete!'"],
319
315
  },
@@ -333,57 +329,67 @@ 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 add` (optional, only set via `gw init --auto-copy-files`)
337
- - **hooks**: Command hooks configuration (optional, set via `gw init --pre-add` and `--post-add`)
338
- - **hooks.add.pre**: Array of commands to run before creating a worktree
339
- - **hooks.add.post**: Array of commands to run after creating a worktree
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 add` or `gw list` (optional, defaults to false, set via `gw init --auto-clean`)
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
- ### add
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
- Create a new git worktree with optional automatic file copying.
347
+ **Aliases:** `co`, `add` (for backwards compatibility)
350
348
 
351
349
  ```bash
352
- gw add <worktree-name> [files...]
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 wraps `git worktree add` and optionally copies files to the new worktree. If `autoCopyFiles` is configured, those files are automatically copied. You can override this by specifying files as arguments.
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 add` 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.
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
- **Remote-First Fetch Approach:**
369
+ **Branch Handling:**
370
+ `gw checkout` intelligently handles different branch scenarios:
361
371
 
362
- The `gw add` command follows a remote-first approach when creating new branches:
372
+ 1. **Local branches**: If the branch already exists locally, it's used directly. No network access required.
363
373
 
364
- 1. **What happens**: When you create a new branch (e.g., `gw add feat/new-feature`), the command:
365
- - Fetches the latest version of the source branch from the remote (e.g., `origin/main`)
366
- - Creates your new branch from the fresh remote ref (e.g., `origin/main`)
367
- - Sets up tracking to `origin/feat/new-feature` for easy pushing
374
+ 2. **Remote-only branches**: If the branch exists only on remote (e.g., `origin/feat/something`), `gw checkout` fetches it and creates a proper local tracking branch. This ensures `git push` and `git pull` work correctly.
368
375
 
369
- 2. **Why it matters**: This ensures your new branch starts from the latest remote code, not from a potentially outdated local branch. This prevents:
370
- - Merge conflicts from missing recent changes
371
- - Building features on old code
372
- - Divergent histories that are hard to reconcile
376
+ 3. **New branches**: If the branch doesn't exist anywhere, it's created from the source branch (defaultBranch or `--from` branch) after fetching the latest from remote.
373
377
 
374
- 3. **Network failure handling**:
375
- - **With `--from <branch>`**: Requires successful remote fetch. If the fetch fails (network issues, branch doesn't exist on remote, authentication problems), the command exits with a detailed error message and troubleshooting steps. This ensures you're working with fresh code when you explicitly specify a source.
376
- - **Without `--from` (default branch)**: Warns about fetch failures but allows creation using the local branch as a fallback. This supports offline development or when no remote is configured.
378
+ **Network Behavior:**
377
379
 
378
- 4. **Offline development**: When working offline or when remote fetch fails for the default branch, the command falls back to using the local branch with a clear warning. This allows you to continue working without network access while being aware that your start point may not be current.
380
+ - **New branches without `--from`**: Fetches defaultBranch from remote, falls back to local if fetch fails (offline support)
381
+ - **New branches with `--from`**: Requires successful remote fetch, exits on failure (ensures fresh code)
382
+ - **Local branches**: Used directly without network access
383
+ - **Remote-only branches**: Fetches and creates local tracking branch, uses cached remote ref if fetch fails
379
384
 
380
385
  **Network Failure Handling:**
381
386
 
382
387
  - When using `--from` with an explicit branch, the command requires a successful fetch from the remote to ensure you're working with the latest code. If the fetch fails (network issues, branch doesn't exist on remote, authentication problems), the command will exit with a detailed error message and suggestions for resolution.
383
- - 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.
388
+ - For local branches, no network is required.
389
+ - For remote-only branches or new branches without `--from`, fetch failures trigger a warning but allow creation using local/cached refs.
384
390
 
385
391
  **Upstream Tracking:**
386
- When `gw add` 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.
392
+ 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
393
 
388
394
  **Git Ref Conflict Detection:**
389
395
  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 +402,7 @@ If you try to add a worktree that already exists, the command will prompt you to
396
402
 
397
403
  #### Arguments
398
404
 
399
- - `<worktree-name>`: Name or path for the new worktree
405
+ - `<branch-name>`: Branch name to checkout or create
400
406
  - `[files...]`: Optional files to copy (overrides `autoCopyFiles` config)
401
407
 
402
408
  #### Options
@@ -416,35 +422,46 @@ All `git worktree add` options are supported:
416
422
  #### Examples
417
423
 
418
424
  ```bash
419
- # Create worktree (auto-copies files if autoCopyFiles is configured)
425
+ # Create worktree for new branch (auto-copies files if autoCopyFiles is configured)
420
426
  # Automatically navigates to new worktree
421
- gw add feat/new-feature
427
+ gw checkout feat/new-feature
428
+ gw co feat/new-feature # Using alias
429
+
430
+ # Navigate to worktree where main is already checked out
431
+ gw checkout main
432
+ # Output: Branch main is checked out in another worktree:
433
+ # /path/to/repo/main
434
+ #
435
+ # Navigating there...
422
436
 
423
437
  # Create worktree without navigating to it
424
- gw add feat/new-feature --no-cd
438
+ gw checkout feat/new-feature --no-cd
425
439
 
426
440
  # Create worktree from a different branch instead of defaultBranch
427
- gw add feat/new-feature --from develop
441
+ gw checkout feat/new-feature --from develop
428
442
 
429
443
  # Create child feature branch from parent feature branch
430
- gw add feat/child-feature --from feat/parent-feature
444
+ gw checkout feat/child-feature --from feat/parent-feature
431
445
 
432
446
  # Create worktree with new branch
433
- gw add feat/new-feature -b my-branch
447
+ gw checkout feat/new-feature -b my-branch
434
448
 
435
449
  # Create worktree and copy specific files (overrides config)
436
- gw add feat/new-feature .env secrets/
450
+ gw checkout feat/new-feature .env secrets/
437
451
 
438
452
  # Force create even if branch exists elsewhere
439
- gw add feat/bugfix -f
453
+ gw checkout feat/bugfix -f
440
454
 
441
- # If worktree already exists, prompts to navigate to it
442
- gw add feat/existing-branch
443
- # Output: Worktree feat/existing-branch already exists at:
444
- # /path/to/repo/feat/existing-branch
455
+ # Create worktree for remote branch (prompts)
456
+ gw checkout remote-feature
457
+ # Output: Branch remote-feature exists on remote but not locally.
445
458
  #
446
- # Navigate to it? [Y/n]:
447
- # (Press Enter to navigate, or 'n' to cancel)
459
+ # Create a new worktree for it? [Y/n]:
460
+ # (If yes, creates the worktree)
461
+
462
+ # Already on the branch
463
+ gw checkout current-branch
464
+ # Output: Already on 'current-branch'
448
465
  ```
449
466
 
450
467
  #### Auto-Copy Configuration
@@ -465,21 +482,21 @@ This creates:
465
482
  }
466
483
  ```
467
484
 
468
- Now every time you run `gw add`, these files will be automatically copied from your default source worktree (usually `main`) to the new worktree.
485
+ 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
486
 
470
487
  #### Hooks
471
488
 
472
- You can configure pre-add and post-add hooks to run commands before and after worktree creation. This is useful for:
489
+ You can configure pre-checkout and post-checkout hooks to run commands before and after worktree creation. This is useful for:
473
490
 
474
- - **Pre-add hooks**: Running validation scripts, checking prerequisites
475
- - **Post-add hooks**: Installing dependencies, setting up the environment
491
+ - **Pre-checkout hooks**: Running validation scripts, checking prerequisites
492
+ - **Post-checkout hooks**: Installing dependencies, setting up the environment
476
493
 
477
494
  ```bash
478
- # Configure a post-add hook to install dependencies
479
- gw init --post-add "pnpm install"
495
+ # Configure a post-checkout hook to install dependencies
496
+ gw init --post-checkout "pnpm install"
480
497
 
481
498
  # Configure multiple hooks
482
- gw init --pre-add "echo 'Creating: {worktree}'" --post-add "pnpm install" --post-add "echo 'Done!'"
499
+ gw init --pre-checkout "echo 'Creating: {worktree}'" --post-checkout "pnpm install" --post-checkout "echo 'Done!'"
483
500
  ```
484
501
 
485
502
  **Hook Variables:**
@@ -493,17 +510,17 @@ Hooks support variable substitution:
493
510
 
494
511
  **Hook Behavior:**
495
512
 
496
- - **Pre-add hooks** run before the worktree is created (in the git root directory). If any pre-add hook fails, the worktree creation is aborted.
497
- - **Post-add hooks** run after the worktree is created and files are copied (in the new worktree directory). If a post-add hook fails, a warning is shown but the worktree creation is considered successful.
513
+ - **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.
514
+ - **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
515
 
499
516
  **Example: Auto-install dependencies**
500
517
 
501
518
  ```bash
502
519
  # One-time setup
503
- gw init --auto-copy-files .env --post-add "pnpm install"
520
+ gw init --auto-copy-files .env --post-checkout "pnpm install"
504
521
 
505
522
  # Now when you create a worktree:
506
- gw add feat/new-feature
523
+ gw checkout feat/new-feature
507
524
  # 1. Creates the worktree
508
525
  # 2. Copies .env file
509
526
  # 3. Runs pnpm install in the new worktree
@@ -547,79 +564,6 @@ The `cd` command integrates with your shell through an automatically installed f
547
564
 
548
565
  **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
566
 
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
567
  ### pr
624
568
 
625
569
  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 +620,8 @@ gw pr 42 --no-cd
676
620
  3. **Checks for existing worktree**: If the branch is already checked out, offers to navigate there
677
621
  4. **Fetches PR branch**: Uses `git fetch origin pull/<number>/head:<branch>` pattern which works for both same-repo and fork PRs
678
622
  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 add`)
680
- 7. **Runs hooks**: Executes pre-add and post-add hooks (same as `gw add`)
623
+ 6. **Copies files**: Auto-copies files from `autoCopyFiles` config (same as `gw checkout`)
624
+ 7. **Runs hooks**: Executes pre-checkout and post-checkout hooks (same as `gw checkout`)
681
625
  8. **Navigates**: Automatically navigates to the new worktree
682
626
 
683
627
  **Fork Handling:**
@@ -786,7 +730,7 @@ Shell integration provides:
786
730
 
787
731
  - **Navigation support**: `gw cd <worktree>` navigates directly to worktrees
788
732
  - **Real-time streaming**: Command output streams as it's generated (no buffering)
789
- - **Auto-navigation**: Automatically navigate after `gw add` and `gw remove` operations
733
+ - **Auto-navigation**: Automatically navigate after `gw checkout` and `gw remove` operations
790
734
  - **Multi-alias support**: Install for different command names (e.g., `gw-dev` for development)
791
735
 
792
736
  ```bash
@@ -884,11 +828,11 @@ gw init [repository-url] [directory] [options]
884
828
  - `-i, --interactive`: Interactively prompt for configuration options
885
829
  - `--root <path>`: Specify the git repository root path (optional, auto-detects if not provided)
886
830
  - `--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 add`
888
- - `--pre-add <command>`: Command to run before `gw add` creates a worktree (can be specified multiple times)
889
- - `--post-add <command>`: Command to run after `gw add` creates a worktree (can be specified multiple times)
831
+ - `--auto-copy-files <files>`: Comma-separated list of files to auto-copy when creating worktrees with `gw checkout`
832
+ - `--pre-checkout <command>`: Command to run before `gw checkout` creates a worktree (can be specified multiple times)
833
+ - `--post-checkout <command>`: Command to run after `gw checkout` creates a worktree (can be specified multiple times)
890
834
  - `--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 add` and `gw list` with 24-hour cooldown)
835
+ - `--auto-clean`: Enable automatic cleanup of stale worktrees (runs on `gw checkout` and `gw list` with 24-hour cooldown)
892
836
  - `--update-strategy <strategy>`: Set default update strategy: 'merge' or 'rebase' (default: merge)
893
837
  - `-h, --help`: Show help message
894
838
 
@@ -901,7 +845,7 @@ Clone a repository and automatically set it up with gw configuration. **This is
901
845
  gw init git@github.com:user/repo.git --interactive
902
846
  # Prompts for:
903
847
  # - Auto-copy files (.env, secrets/, etc.)
904
- # - Pre-add and post-add hooks (pnpm install, etc.)
848
+ # - Pre-checkout and post-checkout hooks (pnpm install, etc.)
905
849
  # - Clean threshold
906
850
  # - Update strategy
907
851
  # Then automatically creates the main worktree and navigates to the repo
@@ -909,7 +853,7 @@ gw init git@github.com:user/repo.git --interactive
909
853
  # Clone with configuration in one command (non-interactive)
910
854
  gw init git@github.com:user/repo.git \
911
855
  --auto-copy-files .env,secrets/ \
912
- --post-add "pnpm install"
856
+ --post-checkout "pnpm install"
913
857
 
914
858
  # Clone into specific directory
915
859
  gw init git@github.com:user/repo.git my-project --interactive
@@ -934,7 +878,7 @@ gw init git@github.com:user/repo.git
934
878
 
935
879
  - No need to manually run `git clone --bare` or `git worktree add`
936
880
  - Configuration is set up immediately
937
- - Ready to use `gw add` right away
881
+ - Ready to use `gw checkout` right away
938
882
 
939
883
  **Notes:**
940
884
 
@@ -958,13 +902,13 @@ gw init
958
902
  gw init --auto-copy-files .env,secrets/
959
903
 
960
904
  # Initialize with post-add hook to install dependencies
961
- gw init --post-add "pnpm install"
905
+ gw init --post-checkout "pnpm install"
962
906
 
963
907
  # Initialize with pre-add validation hook
964
- gw init --pre-add "echo 'Creating worktree: {worktree}'"
908
+ gw init --pre-checkout "echo 'Creating worktree: {worktree}'"
965
909
 
966
910
  # Initialize with multiple hooks
967
- gw init --pre-add "echo 'Starting...'" --post-add "pnpm install" --post-add "echo 'Done!'"
911
+ gw init --pre-checkout "echo 'Starting...'" --post-checkout "pnpm install" --post-checkout "echo 'Done!'"
968
912
 
969
913
  # Initialize with custom default source
970
914
  gw init --default-source master
@@ -979,7 +923,7 @@ gw init --clean-threshold 14
979
923
  gw init --update-strategy rebase
980
924
 
981
925
  # Full configuration example
982
- gw init --auto-copy-files .env,secrets/ --post-add "pnpm install" --clean-threshold 14 --update-strategy merge
926
+ gw init --auto-copy-files .env,secrets/ --post-checkout "pnpm install" --clean-threshold 14 --update-strategy merge
983
927
 
984
928
  # Show help
985
929
  gw init --help
@@ -1006,12 +950,12 @@ gw init --auto-clean
1006
950
  gw init --auto-clean --clean-threshold 14
1007
951
 
1008
952
  # Enable with other options
1009
- gw init --auto-clean --auto-copy-files .env --post-add "pnpm install"
953
+ gw init --auto-clean --auto-copy-files .env --post-checkout "pnpm install"
1010
954
  ```
1011
955
 
1012
956
  **How it works:**
1013
957
 
1014
- - Prompts after `gw add` and `gw list` commands when stale worktrees are detected
958
+ - Prompts after `gw checkout` and `gw list` commands when stale worktrees are detected
1015
959
  - Only prompts once per 24 hours (cooldown)
1016
960
  - **Never removes the `defaultBranch` worktree** - it's protected as the source for file syncing
1017
961
  - Checks for worktrees older than `cleanThreshold` with:
@@ -1081,7 +1025,7 @@ If your `.gw/config.json` contains:
1081
1025
  "defaultBranch": "main",
1082
1026
  "autoCopyFiles": [".env", "secrets/"],
1083
1027
  "hooks": {
1084
- "add": {
1028
+ "checkout": {
1085
1029
  "post": ["pnpm install"]
1086
1030
  }
1087
1031
  },
@@ -1093,7 +1037,7 @@ If your `.gw/config.json` contains:
1093
1037
  Then `gw show-init` will output:
1094
1038
 
1095
1039
  ```bash
1096
- gw init --root /Users/username/Workspace/repo.git --auto-copy-files .env,secrets/ --post-add 'pnpm install' --update-strategy rebase
1040
+ gw init --root /Users/username/Workspace/repo.git --auto-copy-files .env,secrets/ --post-checkout 'pnpm install' --update-strategy rebase
1097
1041
  ```
1098
1042
 
1099
1043
  #### When to Use
@@ -1262,7 +1206,7 @@ gw list -v # Verbose output
1262
1206
 
1263
1207
  #### remove (rm)
1264
1208
 
1265
- Remove a worktree from the repository.
1209
+ Remove a worktree from the repository. By default, also deletes the local branch to prevent orphaned branches.
1266
1210
 
1267
1211
  ```bash
1268
1212
  gw remove <worktree>
@@ -1270,7 +1214,16 @@ gw remove <worktree>
1270
1214
  gw rm <worktree>
1271
1215
  ```
1272
1216
 
1273
- **Protected Branches:**
1217
+ **Branch Cleanup:**
1218
+
1219
+ By default, `gw remove` deletes the local branch after removing the worktree:
1220
+
1221
+ - Uses safe delete (`git branch -d`) which warns if branch has unmerged commits
1222
+ - Use `--preserve-branch` to keep the local branch
1223
+ - Use `--force` to force delete unmerged branches
1224
+ - Protected branches (main, master, defaultBranch, gw_root) are never deleted
1225
+
1226
+ **Protected Worktrees:**
1274
1227
 
1275
1228
  The following worktrees are protected and cannot be removed:
1276
1229
 
@@ -1281,9 +1234,10 @@ The following worktrees are protected and cannot be removed:
1281
1234
  **Examples:**
1282
1235
 
1283
1236
  ```bash
1284
- gw remove feat-branch # Remove a worktree
1285
- gw remove --force feat-branch # Force remove even if dirty
1286
- gw rm feat-branch # Using alias
1237
+ gw remove feat-branch # Remove worktree AND delete local branch
1238
+ gw remove feat-branch --preserve-branch # Remove worktree but KEEP local branch
1239
+ gw remove --force feat-branch # Force remove worktree and force delete branch
1240
+ gw rm feat-branch # Using alias
1287
1241
  ```
1288
1242
 
1289
1243
  #### move (mv)
@@ -1444,7 +1398,7 @@ gw cd feat/new-feature
1444
1398
  ```bash
1445
1399
  # One-time setup: Configure auto-copy files and hooks
1446
1400
  gw init --auto-copy-files .env,components/agents/.env,components/ui/.vercel/ \
1447
- --post-add "pnpm install"
1401
+ --post-checkout "pnpm install"
1448
1402
 
1449
1403
  # From within any worktree of your repository
1450
1404
  # Create a new worktree with auto-copy and hooks
@@ -1667,7 +1621,7 @@ packages/gw-tool/
1667
1621
  │ ├── main.ts # CLI entry point and command dispatcher
1668
1622
  │ ├── index.ts # Public API exports
1669
1623
  │ ├── commands/ # Command implementations
1670
- │ │ ├── add.ts # Add command (create worktree with auto-copy)
1624
+ │ │ ├── checkout.ts # Checkout command (create worktree, switch branches, navigate)
1671
1625
  │ │ ├── copy.ts # Sync command (sync files between worktrees)
1672
1626
  │ │ ├── init.ts # Init command
1673
1627
  │ │ ├── root.ts # Root command
@@ -1702,7 +1656,7 @@ packages/gw-tool/
1702
1656
 
1703
1657
  There are two types of commands you can add:
1704
1658
 
1705
- #### Custom Commands (like `add`, `copy`)
1659
+ #### Custom Commands (like `checkout`, `sync`)
1706
1660
 
1707
1661
  For commands with custom logic, follow the pattern used by existing commands:
1708
1662
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw-tools/gw",
3
- "version": "0.20.12",
3
+ "version": "0.20.14",
4
4
  "description": "A command-line tool for managing git worktrees - copy files between worktrees with ease",
5
5
  "keywords": [
6
6
  "git",