Skip to content

Commit c037dcb

Browse files
mycarrysunclaude
andauthored
fix: use git check-ignore for worktree gitignore verification (obra#160)
* fix: use git check-ignore for worktree gitignore verification The using-git-worktrees skill previously used grep to check only the local .gitignore file, missing patterns in global gitignore configurations (core.excludesfile). This caused unnecessary modifications to local .gitignore when the directory was already globally ignored. Changed verification from grep to git check-ignore, which respects Git's full ignore hierarchy (local, global, and system gitignore files). Fixes obra#101 Tested with: Subagent pressure scenarios verifying correct behavior with global gitignore configuration. Baseline test confirmed the bug, post-fix test confirmed correct behavior. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * style: convert bold emphasis to headings in Common Mistakes section Convert **Title** patterns to ### Title headings for markdown lint compliance (MD036 - no emphasis as heading). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a7a8c08 commit c037dcb

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

skills/using-git-worktrees/SKILL.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ Which would you prefer?
5252

5353
### For Project-Local Directories (.worktrees or worktrees)
5454

55-
**MUST verify .gitignore before creating worktree:**
55+
**MUST verify directory is ignored before creating worktree:**
5656

5757
```bash
58-
# Check if directory pattern in .gitignore
59-
grep -q "^\.worktrees/$" .gitignore || grep -q "^worktrees/$" .gitignore
58+
# Check if directory is ignored (respects local, global, and system gitignore)
59+
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
6060
```
6161

62-
**If NOT in .gitignore:**
62+
**If NOT ignored:**
6363

6464
Per Jesse's rule "Fix broken things immediately":
6565
1. Add appropriate line to .gitignore
@@ -145,29 +145,33 @@ Ready to implement <feature-name>
145145

146146
| Situation | Action |
147147
|-----------|--------|
148-
| `.worktrees/` exists | Use it (verify .gitignore) |
149-
| `worktrees/` exists | Use it (verify .gitignore) |
148+
| `.worktrees/` exists | Use it (verify ignored) |
149+
| `worktrees/` exists | Use it (verify ignored) |
150150
| Both exist | Use `.worktrees/` |
151151
| Neither exists | Check CLAUDE.md → Ask user |
152-
| Directory not in .gitignore | Add it immediately + commit |
152+
| Directory not ignored | Add to .gitignore + commit |
153153
| Tests fail during baseline | Report failures + ask |
154154
| No package.json/Cargo.toml | Skip dependency install |
155155

156156
## Common Mistakes
157157

158-
**Skipping .gitignore verification**
158+
### Skipping ignore verification
159+
159160
- **Problem:** Worktree contents get tracked, pollute git status
160-
- **Fix:** Always grep .gitignore before creating project-local worktree
161+
- **Fix:** Always use `git check-ignore` before creating project-local worktree
162+
163+
### Assuming directory location
161164

162-
**Assuming directory location**
163165
- **Problem:** Creates inconsistency, violates project conventions
164166
- **Fix:** Follow priority: existing > CLAUDE.md > ask
165167

166-
**Proceeding with failing tests**
168+
### Proceeding with failing tests
169+
167170
- **Problem:** Can't distinguish new bugs from pre-existing issues
168171
- **Fix:** Report failures, get explicit permission to proceed
169172

170-
**Hardcoding setup commands**
173+
### Hardcoding setup commands
174+
171175
- **Problem:** Breaks on projects using different tools
172176
- **Fix:** Auto-detect from project files (package.json, etc.)
173177

@@ -177,7 +181,7 @@ Ready to implement <feature-name>
177181
You: I'm using the using-git-worktrees skill to set up an isolated workspace.
178182
179183
[Check .worktrees/ - exists]
180-
[Verify .gitignore - contains .worktrees/]
184+
[Verify ignored - git check-ignore confirms .worktrees/ is ignored]
181185
[Create worktree: git worktree add .worktrees/auth -b feature/auth]
182186
[Run npm install]
183187
[Run npm test - 47 passing]
@@ -190,15 +194,15 @@ Ready to implement auth feature
190194
## Red Flags
191195

192196
**Never:**
193-
- Create worktree without .gitignore verification (project-local)
197+
- Create worktree without verifying it's ignored (project-local)
194198
- Skip baseline test verification
195199
- Proceed with failing tests without asking
196200
- Assume directory location when ambiguous
197201
- Skip CLAUDE.md check
198202

199203
**Always:**
200204
- Follow directory priority: existing > CLAUDE.md > ask
201-
- Verify .gitignore for project-local
205+
- Verify directory is ignored for project-local
202206
- Auto-detect and run project setup
203207
- Verify clean test baseline
204208

0 commit comments

Comments
 (0)