@gw-tools/gw 0.20.12-beta.1 → 0.20.12

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 +54 -49
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -354,27 +354,33 @@ gw add <worktree-name> [files...]
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
356
 
357
- **Branch Handling:**
358
- `gw add` intelligently handles different branch scenarios:
357
+ **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.
359
359
 
360
- 1. **Local branches**: If the branch already exists locally, it's used directly. No network access required.
360
+ **Remote-First Fetch Approach:**
361
361
 
362
- 2. **Remote-only branches**: If the branch exists only on remote (e.g., `origin/feat/something`), `gw add` fetches it and creates a proper local tracking branch. This ensures `git push` and `git pull` work correctly.
362
+ The `gw add` command follows a remote-first approach when creating new branches:
363
363
 
364
- 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.
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
365
368
 
366
- **Network Behavior:**
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
367
373
 
368
- - **New branches without `--from`**: Fetches defaultBranch from remote, falls back to local if fetch fails (offline support)
369
- - **New branches with `--from`**: Requires successful remote fetch, exits on failure (ensures fresh code)
370
- - **Local branches**: Used directly without network access
371
- - **Remote-only branches**: Fetches and creates local tracking branch, uses cached remote ref if fetch fails
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.
377
+
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.
372
379
 
373
380
  **Network Failure Handling:**
374
381
 
375
382
  - 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.
376
- - For local branches, no network is required.
377
- - For remote-only branches or new branches without `--from`, fetch failures trigger a warning but allow creation using local/cached refs.
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.
378
384
 
379
385
  **Upstream Tracking:**
380
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.
@@ -1104,12 +1110,12 @@ Use `gw show-init` to:
1104
1110
  Sync files and directories between worktrees, preserving directory structure.
1105
1111
 
1106
1112
  ```bash
1107
- gw sync [options] <target-worktree> [files...]
1113
+ gw sync [options] [target-worktree] [files...]
1108
1114
  ```
1109
1115
 
1110
1116
  #### Arguments
1111
1117
 
1112
- - `<target-worktree>`: Name or full path of the target worktree
1118
+ - `[target-worktree]`: Name or full path of the target worktree. If omitted, defaults to the current worktree
1113
1119
  - `[files...]`: One or more files or directories to sync (paths relative to worktree root). If omitted, uses `autoCopyFiles` from `.gw/config.json`
1114
1120
 
1115
1121
  #### Options
@@ -1121,7 +1127,10 @@ gw sync [options] <target-worktree> [files...]
1121
1127
  #### Examples
1122
1128
 
1123
1129
  ```bash
1124
- # Sync autoCopyFiles from config (if configured)
1130
+ # Sync autoCopyFiles to current worktree (if inside a worktree)
1131
+ gw sync
1132
+
1133
+ # Sync autoCopyFiles from config to a specific target
1125
1134
  gw sync feat-branch
1126
1135
 
1127
1136
  # Sync .env file from main to feat-branch
@@ -1199,7 +1208,8 @@ The clean command:
1199
1208
  | `gw clean` | No (all worktrees) | Yes (unless --force) | Clean up all finished work |
1200
1209
  | `gw clean --use-autoclean-threshold` | Yes (7+ days) | Yes (unless --force) | Clean up old, stale worktrees |
1201
1210
  | `gw clean --force` | No (all worktrees) | No | Force removal of all worktrees |
1202
- | `gw prune --clean` | No (all worktrees) | No | Git's native cleanup (no gw safety) |
1211
+ | `gw prune` | No (all worktrees) | Yes | Full cleanup (worktrees + branches) |
1212
+ | `gw prune --stale-only` | N/A | N/A | Git passthrough (metadata only) |
1203
1213
 
1204
1214
  **Safety Features:**
1205
1215
 
@@ -1252,7 +1262,7 @@ gw list -v # Verbose output
1252
1262
 
1253
1263
  #### remove (rm)
1254
1264
 
1255
- Remove a worktree from the repository. By default, also deletes the local branch to prevent orphaned branches.
1265
+ Remove a worktree from the repository.
1256
1266
 
1257
1267
  ```bash
1258
1268
  gw remove <worktree>
@@ -1260,16 +1270,7 @@ gw remove <worktree>
1260
1270
  gw rm <worktree>
1261
1271
  ```
1262
1272
 
1263
- **Branch Cleanup:**
1264
-
1265
- By default, `gw remove` deletes the local branch after removing the worktree:
1266
-
1267
- - Uses safe delete (`git branch -d`) which warns if branch has unmerged commits
1268
- - Use `--preserve-branch` to keep the local branch
1269
- - Use `--force` to force delete unmerged branches
1270
- - Protected branches (main, master, defaultBranch, gw_root) are never deleted
1271
-
1272
- **Protected Worktrees:**
1273
+ **Protected Branches:**
1273
1274
 
1274
1275
  The following worktrees are protected and cannot be removed:
1275
1276
 
@@ -1280,10 +1281,9 @@ The following worktrees are protected and cannot be removed:
1280
1281
  **Examples:**
1281
1282
 
1282
1283
  ```bash
1283
- gw remove feat-branch # Remove worktree AND delete local branch
1284
- gw remove feat-branch --preserve-branch # Remove worktree but KEEP local branch
1285
- gw remove --force feat-branch # Force remove worktree and force delete branch
1286
- gw rm feat-branch # Using alias
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
1287
1287
  ```
1288
1288
 
1289
1289
  #### move (mv)
@@ -1305,13 +1305,13 @@ gw mv feat-branch ../new-location
1305
1305
 
1306
1306
  #### prune
1307
1307
 
1308
- Clean up worktree administrative data and optionally remove clean worktrees.
1308
+ Clean up worktrees and orphan branches. By default, performs full cleanup (removes clean worktrees AND deletes orphan branches).
1309
1309
 
1310
- **Standard Mode** (without `--clean`):
1311
- Wraps `git worktree prune` to clean up administrative files for deleted worktrees.
1310
+ **Default Mode (full cleanup):**
1311
+ Removes worktrees that are safe to delete (no uncommitted changes, no unpushed commits) AND deletes orphan branches (branches without associated worktrees).
1312
1312
 
1313
- **Clean Mode** (with `--clean`):
1314
- First runs `git worktree prune`, then removes ALL worktrees that have no uncommitted changes, no staged files, and no unpushed commits. This is similar to default `gw clean` behavior but with additional protections for the default branch.
1313
+ **Stale-Only Mode** (with `--stale-only`):
1314
+ Git passthrough - only cleans up administrative files for deleted worktrees. Does not remove worktrees or branches.
1315
1315
 
1316
1316
  ```bash
1317
1317
  gw prune [options]
@@ -1319,42 +1319,47 @@ gw prune [options]
1319
1319
 
1320
1320
  **Options:**
1321
1321
 
1322
- - `--clean` - Enable clean mode (remove clean worktrees)
1322
+ - `--stale-only` - Git passthrough mode (only metadata cleanup)
1323
+ - `--no-branches` - Skip orphan branch cleanup (worktrees only)
1323
1324
  - `-n, --dry-run` - Preview what would be removed
1324
1325
  - `-f, --force` - Skip confirmation prompt
1325
1326
  - `-v, --verbose` - Show detailed output
1326
1327
  - `-h, --help` - Show help
1327
1328
 
1328
- **Safety Features** (in clean mode):
1329
+ **Safety Features:**
1329
1330
 
1330
1331
  - Default branch is protected (configured in `.gw/config.json`)
1331
1332
  - gw_root branch is protected (bare repository root)
1332
1333
  - Current worktree cannot be removed
1333
1334
  - Bare repository is never removed
1334
- - Confirmation prompt before removal (defaults to yes, just press Enter to confirm)
1335
+ - Branches with unpushed commits are protected
1336
+ - Confirmation prompt before removal (defaults to yes)
1335
1337
 
1336
1338
  **Examples:**
1337
1339
 
1338
1340
  ```bash
1339
- # Standard prune (cleanup administrative data)
1340
- gw prune
1341
- gw prune --verbose
1341
+ # Full cleanup (default) - removes worktrees AND orphan branches
1342
+ gw prune # Remove clean worktrees and orphan branches
1343
+ gw prune --dry-run # Preview what would be removed
1344
+ gw prune --force # Skip confirmation
1345
+ gw prune --verbose # Show detailed output
1346
+
1347
+ # Skip branch cleanup
1348
+ gw prune --no-branches # Only clean worktrees, keep branches
1342
1349
 
1343
- # Clean mode (remove clean worktrees)
1344
- gw prune --clean # Remove all clean worktrees (with prompt)
1345
- gw prune --clean --dry-run # Preview what would be removed
1346
- gw prune --clean --force # Remove without confirmation
1347
- gw prune --clean --verbose # Show detailed output
1350
+ # Git passthrough (stale-only)
1351
+ gw prune --stale-only # Only clean git metadata (like git worktree prune)
1348
1352
  ```
1349
1353
 
1350
1354
  **Comparison with `gw clean`:**
1351
- | Feature | `gw clean` | `gw clean --use-autoclean-threshold` | `gw prune --clean` |
1355
+ | Feature | `gw clean` | `gw clean --use-autoclean-threshold` | `gw prune` |
1352
1356
  |---------|-----------|-------------------------------------|-------------------|
1353
1357
  | Age-based | No (all worktrees) | Yes (configurable threshold) | No (removes all clean) |
1354
1358
  | Safety checks | Yes | Yes | Yes |
1355
1359
  | Protects default branch | No | No | Yes |
1360
+ | Deletes orphan branches | No | No | Yes |
1356
1361
  | Runs `git worktree prune` | No | No | Yes |
1357
- | Use case | Clean up finished work | Regular maintenance | Aggressive cleanup |
1362
+ | Use case | Clean up finished work | Regular maintenance | Full cleanup |
1358
1363
 
1359
1364
  #### lock
1360
1365
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gw-tools/gw",
3
- "version": "0.20.12-beta.1",
3
+ "version": "0.20.12",
4
4
  "description": "A command-line tool for managing git worktrees - copy files between worktrees with ease",
5
5
  "keywords": [
6
6
  "git",