commands
This commit is contained in:
@@ -1,8 +1,91 @@
|
||||
---
|
||||
description: Start a new feature in a git worktree
|
||||
description: Start parallel work on a feature using git worktree
|
||||
---
|
||||
In a worktrees directory inside the git project's root, create a new worktree for the requested feature.
|
||||
create the directory if it doesn't exist.
|
||||
keep the branch name concise, and don't include "opencode" in its name.
|
||||
do all the work for the feature in the new worktree.
|
||||
run "kitty @ set-tab-title" to set the tab title of this kitty session to "<project>/<feature>"
|
||||
|
||||
# Start Worktree for Feature
|
||||
|
||||
Initialize a new git worktree to work on a feature in parallel with your current work.
|
||||
|
||||
**Usage:** `/work "feature description"`
|
||||
**Manual:** `/work branch-name`
|
||||
|
||||
**Arguments:**
|
||||
- `$1`: Feature description (quoted) OR branch name (single word)
|
||||
|
||||
## Requirements
|
||||
|
||||
- Must run from the main repository (not inside an existing worktree)
|
||||
- Git installed, repository clean or stashable
|
||||
- Worktrees live in `worktrees/` inside the repo root
|
||||
|
||||
## Process
|
||||
|
||||
### 1. Pre-flight Checks
|
||||
|
||||
```bash
|
||||
# Ensure we're in a git repo
|
||||
git rev-parse --git-dir > /dev/null
|
||||
|
||||
# Ensure not already in a worktree
|
||||
CURRENT_GIT_DIR=$(git rev-parse --git-common-dir)
|
||||
if [[ "$CURRENT_GIT_DIR" == *".git/worktrees"* ]]; then
|
||||
echo "❌ Error: already inside a worktree"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure clean (or stash)
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
echo "⚠️ Working tree has changes"
|
||||
git status --short
|
||||
echo "Stash before creating worktree"
|
||||
git stash push -m "Auto-stash before worktree"
|
||||
fi
|
||||
```
|
||||
|
||||
### 2. Determine Base Branch
|
||||
|
||||
```bash
|
||||
if git show-ref --verify --quiet refs/heads/main; then
|
||||
BASE_BRANCH="main"
|
||||
elif git show-ref --verify --quiet refs/heads/master; then
|
||||
BASE_BRANCH="master"
|
||||
else
|
||||
echo "❌ Error: Cannot auto-detect base branch"
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
|
||||
### 3. Determine Branch Name
|
||||
|
||||
If `$1` contains spaces, treat it as a description and generate a concise branch name.
|
||||
|
||||
Rules:
|
||||
- Lowercase, hyphens, max 50 chars
|
||||
- Prefer `feat/`, `fix/`, `refactor/`, `chore/` prefixes when obvious
|
||||
|
||||
If `$1` is a single word, use it directly.
|
||||
|
||||
**Do not include "opencode" in the branch name.**
|
||||
|
||||
### 4. Create Worktree
|
||||
|
||||
```bash
|
||||
REPO_ROOT=$(git rev-parse --show-toplevel)
|
||||
WORKTREES_DIR="$REPO_ROOT/worktrees"
|
||||
mkdir -p "$WORKTREES_DIR"
|
||||
|
||||
WORKTREE_PATH="$WORKTREES_DIR/$BRANCH_NAME"
|
||||
git worktree add -b "$BRANCH_NAME" "$WORKTREE_PATH" "$BASE_BRANCH"
|
||||
```
|
||||
|
||||
### 5. Next Steps
|
||||
|
||||
```bash
|
||||
cd "$WORKTREE_PATH"
|
||||
git status
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Use `/worktree-compare` to review changes before merging.
|
||||
- Use `/merge` when ready to integrate.
|
||||
|
||||
Reference in New Issue
Block a user