$npx -y skills add aviflombaum/claude-code-in-avinyc --skill rails-worktreeThis skill should be used when the user asks to "create a worktree", "new worktree", "worktree for feature", "git worktree", or needs to work on a feature branch in isolation. Handles Rails-specific credential symlinking (master.key, environment keys) automatically.
| 1 | # Git Worktree for Rails |
| 2 | |
| 3 | Create isolated git worktrees for feature development with automatic Rails credential symlinking. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - Starting work on a new feature that needs isolation |
| 8 | - Working on multiple features simultaneously |
| 9 | - Need a clean environment without stashing changes |
| 10 | |
| 11 | ## Worktree Location |
| 12 | |
| 13 | Worktrees are created in a sibling directory to keep the project root clean: |
| 14 | |
| 15 | ``` |
| 16 | parent/ |
| 17 | project/ # main repo |
| 18 | project-worktrees/ # worktree container |
| 19 | 25-01-22-feature/ # individual worktree |
| 20 | ``` |
| 21 | |
| 22 | The container directory is `../<project-name>-worktrees/` relative to the project root. |
| 23 | |
| 24 | ## Branch Naming Convention |
| 25 | |
| 26 | Format: `YY-MM-DD-feature-description` |
| 27 | |
| 28 | Examples: |
| 29 | - `25-01-22-add-password-reset` |
| 30 | - `25-01-22-fix-api-timeout` |
| 31 | - `25-01-22-refactor-auth-module` |
| 32 | |
| 33 | ## Workflow |
| 34 | |
| 35 | ### Step 1: Get Feature Name |
| 36 | |
| 37 | If no feature name provided, ask: |
| 38 | |
| 39 | ``` |
| 40 | What feature are you working on? (e.g., "add password reset", "fix checkout bug") |
| 41 | ``` |
| 42 | |
| 43 | ### Step 2: Create Worktree |
| 44 | |
| 45 | ```bash |
| 46 | # Get project info |
| 47 | PROJECT_ROOT=$(pwd) |
| 48 | PROJECT_NAME=$(basename "$PROJECT_ROOT") |
| 49 | WORKTREES_DIR="../${PROJECT_NAME}-worktrees" |
| 50 | |
| 51 | # Format branch name: YY-MM-DD-feature-description |
| 52 | DATE=$(date +%y-%m-%d) |
| 53 | BRANCH_NAME="${DATE}-<feature-slug>" |
| 54 | |
| 55 | # Create worktrees directory if needed |
| 56 | mkdir -p "$WORKTREES_DIR" |
| 57 | |
| 58 | # Create worktree with new branch |
| 59 | git worktree add "$WORKTREES_DIR/$BRANCH_NAME" -b "$BRANCH_NAME" |
| 60 | ``` |
| 61 | |
| 62 | ### Step 3: Symlink Rails Credentials |
| 63 | |
| 64 | Rails credentials must be symlinked so the worktree can decrypt secrets: |
| 65 | |
| 66 | ```bash |
| 67 | WORKTREE_PATH="$WORKTREES_DIR/$BRANCH_NAME" |
| 68 | |
| 69 | # master.key |
| 70 | ln -sf "$PROJECT_ROOT/config/master.key" "$WORKTREE_PATH/config/master.key" |
| 71 | |
| 72 | # development.key (if exists) |
| 73 | if [ -f "$PROJECT_ROOT/config/credentials/development.key" ]; then |
| 74 | mkdir -p "$WORKTREE_PATH/config/credentials" |
| 75 | ln -sf "$PROJECT_ROOT/config/credentials/development.key" "$WORKTREE_PATH/config/credentials/development.key" |
| 76 | fi |
| 77 | |
| 78 | # test.key (if exists) |
| 79 | if [ -f "$PROJECT_ROOT/config/credentials/test.key" ]; then |
| 80 | mkdir -p "$WORKTREE_PATH/config/credentials" |
| 81 | ln -sf "$PROJECT_ROOT/config/credentials/test.key" "$WORKTREE_PATH/config/credentials/test.key" |
| 82 | fi |
| 83 | ``` |
| 84 | |
| 85 | Use full absolute paths for symlinks. |
| 86 | |
| 87 | ### Step 4: Report Success |
| 88 | |
| 89 | ``` |
| 90 | Worktree created: |
| 91 | Branch: 25-01-22-add-password-reset |
| 92 | Location: ../project-worktrees/25-01-22-add-password-reset |
| 93 | |
| 94 | Rails credentials symlinked: |
| 95 | - config/master.key |
| 96 | - config/credentials/development.key |
| 97 | - config/credentials/test.key |
| 98 | |
| 99 | To start working: |
| 100 | cd ../project-worktrees/25-01-22-add-password-reset |
| 101 | ``` |
| 102 | |
| 103 | ## Managing Worktrees |
| 104 | |
| 105 | **List worktrees:** |
| 106 | ```bash |
| 107 | git worktree list |
| 108 | ``` |
| 109 | |
| 110 | **Remove worktree:** |
| 111 | ```bash |
| 112 | git worktree remove ../project-worktrees/25-01-22-feature-name |
| 113 | ``` |
| 114 | |
| 115 | **Prune stale worktrees:** |
| 116 | ```bash |
| 117 | git worktree prune |
| 118 | ``` |
| 119 | |
| 120 | ## Example Session |
| 121 | |
| 122 | ``` |
| 123 | User: create a worktree for adding stripe webhooks |
| 124 | |
| 125 | Creating worktree... |
| 126 | Project: vc-matcher-app |
| 127 | Feature: adding stripe webhooks |
| 128 | Branch: 25-01-22-add-stripe-webhooks |
| 129 | |
| 130 | $ mkdir -p ../vc-matcher-app-worktrees |
| 131 | $ git worktree add ../vc-matcher-app-worktrees/25-01-22-add-stripe-webhooks -b 25-01-22-add-stripe-webhooks |
| 132 | |
| 133 | Symlinking Rails credentials... |
| 134 | $ ln -sf /Users/avi/Development/code/project/config/master.key ../vc-matcher-app-worktrees/25-01-22-add-stripe-webhooks/config/master.key |
| 135 | [additional symlinks...] |
| 136 | |
| 137 | Done! Worktree ready at: |
| 138 | ../vc-matcher-app-worktrees/25-01-22-add-stripe-webhooks |
| 139 | ``` |
| 140 | |
| 141 | ## Notes |
| 142 | |
| 143 | - Always use absolute paths for credential symlinks |
| 144 | - The worktree shares git history with main repo |
| 145 | - Commits in worktree are visible from main repo |
| 146 | - Delete the branch separately after removing worktree if needed |
| 147 | - Run `bundle install` in new worktree if Gemfile differs |