You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
📋 Refactor git-worktree-task workflow for clarity and practicality
Restructured guide to emphasize why worktrees matter and practical
setup details. Added port isolation section to prevent dev server
conflicts. Simplified verbose sections and removed redundant bash
examples. Tightened language throughout for better readability.
Copy file name to clipboardExpand all lines: .cursor/rules/git-worktree-task.mdc
+24-46Lines changed: 24 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -6,96 +6,74 @@ alwaysApply: false
6
6
# Git Worktree Task Workflow
7
7
8
8
<objective>
9
-
Deliver a pull request that passes all checks and merges without back-and-forth. Work in isolated git worktrees to keep the main directory clean and allow context switching.
9
+
Deliver a pull request that passes all checks and merges without back-and-forth. Work in isolated git worktrees to keep the main directory clean and allow context switching between tasks.
10
10
</objective>
11
11
12
-
<workspace-setup>
13
-
Create git worktree in .gitworktrees/ directory:
14
-
15
-
```bash
16
-
mkdir -p .gitworktrees
17
-
git worktree add -b feature/task-name .gitworktrees/task-name main
18
-
cd .gitworktrees/task-name
19
-
```
12
+
<why-worktrees>
13
+
Worktrees isolate task branches in separate directories. Your main repo stays on main for quick reference. Your task directory is completely separate. You can switch between them instantly. When done, the worktree disappears cleanly. This is faster and cleaner than stashing or branch switching.
14
+
</why-worktrees>
20
15
16
+
<workspace-setup>
17
+
Create git worktree as a sibling directory (not nested inside the repo). Sibling directories avoid module resolution issues with ESLint, monorepo tools, and symlinked dependencies that break when worktrees are nested.
21
18
</workspace-setup>
22
19
23
-
<environment-initialization>
24
-
Run /setup-environment to prepare the worktree. This detects project type and sets up dependencies, code generation, and environment files.
25
-
26
-
If /setup-environment doesn't exist, set up manually based on project type (Node.js:
Each worktree needs its own port for dev servers to avoid conflicts when running multiple tasks. Create a `.env.local` in the worktree with a unique PORT based on the task name (hash the name to a port offset from 3000, or use sequential assignment). This prevents "port already in use" errors and makes it clear which server belongs to which task.
22
+
</port-isolation>
28
23
29
-
Copy environment files from parent directory if needed. After proper setup, all tests
30
-
(unit + integration) should pass. </environment-initialization>
24
+
<environment-initialization>
25
+
Run /setup-environment if available, otherwise install dependencies and set up environment files manually. After proper setup, all tests (unit + integration) should pass.
26
+
</environment-initialization>
31
27
32
28
<standards-discovery>
33
29
Read all cursor rules in .cursor/rules/. If CLAUDE.md or AGENTS.md exist at project root, read those too. Every applicable rule must be followed.
34
30
</standards-discovery>
35
31
36
32
<implementation>
37
-
Write code that solves the problem following all cursor rules. Make commits along the way as logical units of work are completed. Follow git commit message guidelines in .cursor/rules/git-commit-message.mdc.
33
+
Write code that solves the problem following all cursor rules. Make commits along the way as logical units of work are completed. Follow git commit message guidelines in .cursor/rules/git-commit-message.mdc if it exists.
38
34
</implementation>
39
35
40
36
<local-validation>
41
-
Run project's pre-push validation before pushing. This catches issues before CI:
42
-
- Node.js: `pnpm pre-push` or check package.json scripts
43
-
- Python: `pre-commit run --all-files`, `pytest`, `ruff check`, `mypy`
Check .github/workflows/ to see what CI runs - run those steps locally.
49
-
50
-
All tests should pass after environment setup. If tests fail, it's either incomplete
51
-
setup or bugs in your code. Fix before pushing. </local-validation>
37
+
Run the project's pre-push validation before pushing. Check .github/workflows/ to see what CI runs and run those steps locally first. Local validation catches issues in seconds vs waiting for CI. All tests must pass before pushing.
38
+
</local-validation>
52
39
53
40
<self-review>
54
41
Invoke code reviewer agent (Rivera in .claude/agents/rivera.md if available) to review changes before pushing. Address critical issues, consider warnings seriously, evaluate suggestions for merit. Learn from feedback.
55
42
</self-review>
56
43
57
44
<pull-request-creation>
58
-
Once local validation passes and code review is addressed, push commits. Create pull request with clear description of what changed and why. Help reviewers understand context and decisions made.
45
+
Push commits and create pull request with clear description of what changed and why. Help reviewers understand context and decisions made.
59
46
</pull-request-creation>
60
47
61
48
<ci-validation>
62
49
Let all CI jobs run to completion. All must pass. Green checks required before merge. If CI fails, read logs carefully, understand what broke and why, fix and push again.
63
50
</ci-validation>
64
51
65
52
<bot-review-handling>
66
-
AI code review bots will analyze the pull request. Evaluate feedback critically - you have full project context, bots don't.
53
+
AI code review bots will analyze the pull request. Evaluate feedback critically—you have full project context, bots don't.
67
54
68
55
Fix valuable feedback that identifies real issues. Mark as WONTFIX with clear reasoning
69
56
if feedback is incorrect, not applicable, conflicts with project standards, or would
70
57
break functionality.
71
58
72
-
Be discerning. You are smarter than the bots. </bot-review-handling>
59
+
You are smarter than the bots. Be discerning. </bot-review-handling>
73
60
74
61
<merge-and-cleanup>
75
-
Once CI is green, bot reviews are addressed, and all checks pass, merge the PR.
76
-
77
-
After merge, clean up worktree:
78
-
79
-
```bash
80
-
cd ../.. # Return to main directory
81
-
git worktree remove .gitworktrees/task-name
82
-
```
83
-
62
+
Once CI is green, bot reviews are addressed, and all checks pass, merge the PR. After merge, remove the worktree.
84
63
</merge-and-cleanup>
85
64
86
65
<critical-success-factors>
87
-
Environment setup is not optional. After creating worktree, run /setup-environment or manually install dependencies. Type errors and test failures often stem from missing code generation or dependencies.
66
+
Environment setup is not optional. Type errors and test failures often stem from missing code generation or dependencies.
88
67
89
68
Local validation saves time. Don't push without running pre-push checks. Local tooling
90
69
catches issues in seconds vs waiting for CI.
91
70
92
71
Bot feedback requires judgment. Bots provide suggestions, not mandates. Evaluate each
93
72
piece based on your context and project standards.
94
73
95
-
Full test suite must pass. After setup, all tests (unit + integration) should pass. Fix
96
-
setup or code before pushing.
74
+
Full test suite must pass after setup. Fix setup or code before pushing.
97
75
98
-
Successful autonomous task means: original request completed, all automated checks pass,
0 commit comments