|
| 1 | +<!-- SPDX-License-Identifier: CC-BY-4.0 --> |
| 2 | +<!-- Copyright Contributors to the OpenVDB Project --> |
| 3 | + |
| 4 | +# fvdb Worktree Tools |
| 5 | + |
| 6 | +Developer tools for managing Git worktrees across fvdb-core and fvdb-reality-capture repositories. These tools enable parallel development workflows where you can have multiple branches checked out simultaneously. |
| 7 | + |
| 8 | +## Why Worktrees? |
| 9 | + |
| 10 | +Git worktrees allow you to have multiple branches checked out at the same time in different directories. This is useful for: |
| 11 | + |
| 12 | +- Working on multiple features in parallel |
| 13 | +- Having multiple AI agents working on different issues simultaneously |
| 14 | +- Quick context switching without stashing changes |
| 15 | +- Keeping your main branch clean while working on features |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +### Quick Install |
| 20 | + |
| 21 | +```bash |
| 22 | +cd devtools/worktree |
| 23 | +./install.sh |
| 24 | +``` |
| 25 | + |
| 26 | +The install script will: |
| 27 | +1. Copy the tools to `~/bin` |
| 28 | +2. Add `~/bin` to your PATH (if needed) |
| 29 | +3. Create a configuration file (`~/.fvdb-devtools.conf`) |
| 30 | + |
| 31 | +### Manual Install |
| 32 | + |
| 33 | +```bash |
| 34 | +# Copy scripts |
| 35 | +mkdir -p ~/bin |
| 36 | +cp fvdb-open fvdb-issue fvdb-close ~/bin/ |
| 37 | +chmod +x ~/bin/fvdb-{open,issue,close} |
| 38 | + |
| 39 | +# Add to PATH (add to ~/.bashrc or ~/.zshrc) |
| 40 | +export PATH="$HOME/bin:$PATH" |
| 41 | + |
| 42 | +# Create config file |
| 43 | +cat > ~/.fvdb-devtools.conf << 'EOF' |
| 44 | +FVDB_CORE_PATH=/path/to/fvdb-core |
| 45 | +FVDB_RC_PATH=/path/to/fvdb-reality-capture |
| 46 | +EOF |
| 47 | +``` |
| 48 | + |
| 49 | +## Configuration |
| 50 | + |
| 51 | +Create `~/.fvdb-devtools.conf` with your repository paths: |
| 52 | + |
| 53 | +```bash |
| 54 | +# Required: paths to your main repository clones |
| 55 | +FVDB_CORE_PATH=/home/yourname/github/fvdb-core |
| 56 | +FVDB_RC_PATH=/home/yourname/github/fvdb-reality-capture |
| 57 | + |
| 58 | +# Optional: GitHub repository names (these are the defaults) |
| 59 | +FVDB_CORE_GH_REPO=openvdb/fvdb |
| 60 | +FVDB_RC_GH_REPO=openvdb/fvdb-reality-capture |
| 61 | +``` |
| 62 | + |
| 63 | +Alternatively, set these as environment variables. |
| 64 | + |
| 65 | +## Requirements |
| 66 | + |
| 67 | +- **Git** - with worktree support (Git 2.5+) |
| 68 | +- **Bash 4.0+** - scripts use Bash 4 features; macOS ships Bash 3.2, so install a newer version via `brew install bash` |
| 69 | +- **GitHub CLI** (`gh`) - for `fvdb-issue` to fetch issue details |
| 70 | +- **jq** - for `fvdb-issue` to parse JSON |
| 71 | +- **Cursor IDE** - or set `FVDB_EDITOR_CMD` to your preferred editor (e.g., `code`) |
| 72 | +- **Optional: `claude` CLI** - required only if you use the `--claude` flag with `fvdb-issue` |
| 73 | +- **Linux recommended** - `fvdb-close` "in use" detection uses `/proc` on Linux; on macOS it falls back to `lsof` (slower, may miss some processes) |
| 74 | + |
| 75 | +Install requirements: |
| 76 | +```bash |
| 77 | +# Ubuntu/Debian |
| 78 | +sudo apt-get install jq |
| 79 | +# GitHub CLI: https://cli.github.com/ |
| 80 | + |
| 81 | +# macOS |
| 82 | +brew install bash jq gh |
| 83 | +``` |
| 84 | + |
| 85 | +## Tools |
| 86 | + |
| 87 | +### fvdb-open |
| 88 | + |
| 89 | +Interactive launcher for opening worktrees in Cursor. |
| 90 | + |
| 91 | +```bash |
| 92 | +# Interactive mode - select worktrees from a menu |
| 93 | +fvdb-open |
| 94 | + |
| 95 | +# Direct mode - specify worktrees by branch name |
| 96 | +fvdb-open --core=main --rc=feature-branch |
| 97 | + |
| 98 | +# Help |
| 99 | +fvdb-open --help |
| 100 | +``` |
| 101 | + |
| 102 | +**Features:** |
| 103 | +- Lists all existing worktrees for both repositories |
| 104 | +- Create new worktrees on new or existing branches |
| 105 | +- Opens both repositories in a single Cursor multi-root workspace |
| 106 | + |
| 107 | +### fvdb-issue |
| 108 | + |
| 109 | +Create a worktree for a specific GitHub issue with AI agent context. |
| 110 | + |
| 111 | +```bash |
| 112 | +# By issue number (auto-detects repository) |
| 113 | +fvdb-issue 187 |
| 114 | + |
| 115 | +# By full URL |
| 116 | +fvdb-issue https://github.com/openvdb/fvdb-reality-capture/issues/187 |
| 117 | + |
| 118 | +# Open in Claude Code instead of Cursor |
| 119 | +fvdb-issue 187 --claude |
| 120 | + |
| 121 | +# Specify fvdb-core branch to use |
| 122 | +fvdb-issue 187 --core=my-feature |
| 123 | + |
| 124 | +# Help |
| 125 | +fvdb-issue --help |
| 126 | +``` |
| 127 | + |
| 128 | +**Features:** |
| 129 | +- Fetches issue title, description, labels, and assignees |
| 130 | +- Creates a branch named `issue-{number}-{title-slug}` |
| 131 | +- Creates `.cursor/rules/current-issue.md` with issue context for AI agents |
| 132 | +- Warns if issue is closed or is actually a PR |
| 133 | +- Copies a starter prompt to clipboard for Cursor |
| 134 | +- Supports Claude Code with auto-start (`--claude`) |
| 135 | + |
| 136 | +### fvdb-close |
| 137 | + |
| 138 | +Remove worktrees safely. |
| 139 | + |
| 140 | +```bash |
| 141 | +# Interactive mode - shows all worktrees to choose from |
| 142 | +fvdb-close |
| 143 | + |
| 144 | +# By name (partial match supported) |
| 145 | +fvdb-close issue-187 |
| 146 | +fvdb-close mcmc |
| 147 | + |
| 148 | +# By full path |
| 149 | +fvdb-close /path/to/worktree |
| 150 | + |
| 151 | +# Help |
| 152 | +fvdb-close --help |
| 153 | +``` |
| 154 | + |
| 155 | +**Features:** |
| 156 | +- Lists all worktrees from both repositories |
| 157 | +- Detects if worktree is in use (terminals with cwd there) |
| 158 | +- Prompts to delete the branch after removing worktree |
| 159 | +- Handles detached HEAD worktrees gracefully |
| 160 | + |
| 161 | +## Workflow Examples |
| 162 | + |
| 163 | +### Working on a GitHub Issue |
| 164 | + |
| 165 | +```bash |
| 166 | +# 1. Start working on issue #187 |
| 167 | +fvdb-issue 187 |
| 168 | + |
| 169 | +# 2. Cursor opens with issue context in .cursor/rules/current-issue.md |
| 170 | +# 3. Paste the clipboard prompt to start the AI agent |
| 171 | +# 4. Work on the issue... |
| 172 | + |
| 173 | +# 5. When done, close the worktree |
| 174 | +fvdb-close issue-187 |
| 175 | +# Optionally delete the branch when prompted |
| 176 | +``` |
| 177 | + |
| 178 | +### Multiple Parallel Agents |
| 179 | + |
| 180 | +```bash |
| 181 | +# Terminal 1: Work on issue #100 |
| 182 | +fvdb-issue 100 --claude |
| 183 | + |
| 184 | +# Terminal 2: Work on issue #200 |
| 185 | +fvdb-issue 200 --claude |
| 186 | + |
| 187 | +# Terminal 3: Manual work on a feature |
| 188 | +fvdb-open --core=main --rc=my-feature |
| 189 | +``` |
| 190 | + |
| 191 | +### Quick Feature Branch |
| 192 | + |
| 193 | +```bash |
| 194 | +# 1. Open the launcher |
| 195 | +fvdb-open |
| 196 | + |
| 197 | +# 2. Select "n" for new worktree |
| 198 | +# 3. Choose "1) Create new branch" |
| 199 | +# 4. Enter branch name: my-feature |
| 200 | + |
| 201 | +# 5. Cursor opens with the new worktree |
| 202 | +``` |
| 203 | + |
| 204 | +## Directory Structure |
| 205 | + |
| 206 | +When you create worktrees, they are placed alongside your main repository: |
| 207 | + |
| 208 | +``` |
| 209 | +~/github/ |
| 210 | +├── fvdb-core/ # Main clone (stays on main) |
| 211 | +├── fvdb-core-my-feature/ # Worktree for my-feature branch |
| 212 | +├── fvdb-core-issue-123/ # Worktree for issue #123 |
| 213 | +├── fvdb-reality-capture/ # Main clone |
| 214 | +├── fvdb-reality-capture-issue-187/ |
| 215 | +└── fvdb-reality-capture-experiment/ |
| 216 | +``` |
| 217 | + |
| 218 | +## Tips |
| 219 | + |
| 220 | +1. **Keep main clean**: Leave your main clones on the `main` branch. Use worktrees for all feature work. |
| 221 | + |
| 222 | +2. **One issue per worktree**: Create a dedicated worktree for each issue you're working on. |
| 223 | + |
| 224 | +3. **Clean up regularly**: Use `fvdb-close` to remove worktrees you're done with. This keeps your disk clean and git refs tidy. |
| 225 | + |
| 226 | +4. **Use Claude Code for automation**: The `--claude` flag with `fvdb-issue` auto-starts Claude Code with the issue context, perfect for automated workflows. |
| 227 | + |
| 228 | +5. **Visual differentiation**: Install the Peacock VS Code extension to color-code different worktree windows. |
| 229 | + |
| 230 | +## Troubleshooting |
| 231 | + |
| 232 | +### "FVDB_CORE_PATH is not set" |
| 233 | + |
| 234 | +Create the config file: |
| 235 | +```bash |
| 236 | +cat > ~/.fvdb-devtools.conf << 'EOF' |
| 237 | +FVDB_CORE_PATH=/your/path/to/fvdb-core |
| 238 | +FVDB_RC_PATH=/your/path/to/fvdb-reality-capture |
| 239 | +EOF |
| 240 | +``` |
| 241 | + |
| 242 | +### "command not found: fvdb-open" |
| 243 | + |
| 244 | +Ensure `~/bin` is in your PATH: |
| 245 | +```bash |
| 246 | +export PATH="$HOME/bin:$PATH" |
| 247 | +``` |
| 248 | + |
| 249 | +Add this to your `~/.bashrc` or `~/.zshrc` to make it permanent. |
| 250 | + |
| 251 | +### Worktree shows as "detached" |
| 252 | + |
| 253 | +This happens when a worktree is created for a commit rather than a branch. To fix: |
| 254 | +1. Close the worktree: `fvdb-close <name>` |
| 255 | +2. Create a new one using `fvdb-open` and select "Use existing branch" |
| 256 | + |
| 257 | +### "gh" command not found |
| 258 | + |
| 259 | +Install the GitHub CLI: https://cli.github.com/ |
| 260 | + |
| 261 | +### Clipboard not working |
| 262 | + |
| 263 | +On Linux without a display (SSH), clipboard operations won't work. The prompt will be printed to the terminal instead. |
| 264 | + |
| 265 | +## Uninstalling |
| 266 | + |
| 267 | +```bash |
| 268 | +cd devtools/worktree |
| 269 | +./install.sh --uninstall |
| 270 | +``` |
| 271 | + |
| 272 | +Or manually: |
| 273 | +```bash |
| 274 | +rm ~/bin/fvdb-{open,issue,close} |
| 275 | +rm ~/.fvdb-devtools.conf # Optional |
| 276 | +``` |
0 commit comments