From c319e2be6d87b64727cb2edb361f16d0833d31da Mon Sep 17 00:00:00 2001 From: Drew Ritter Date: Mon, 23 Mar 2026 13:06:23 -0700 Subject: [PATCH] feat(finishing-a-development-branch): add Step 5 cleanup guard (PRI-823) Re-detect externally managed worktree at cleanup time and skip removal. Also fixes pre-existing inconsistency: cleanup now correctly says Options 1 and 4 only, matching Quick Reference and Common Mistakes. Co-Authored-By: Claude Opus 4.6 (1M context) --- skills/finishing-a-development-branch/SKILL.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/skills/finishing-a-development-branch/SKILL.md b/skills/finishing-a-development-branch/SKILL.md index 9ea42d2a..e92ed9e8 100644 --- a/skills/finishing-a-development-branch/SKILL.md +++ b/skills/finishing-a-development-branch/SKILL.md @@ -179,7 +179,16 @@ Then: Cleanup worktree (Step 5) ### Step 5: Cleanup Worktree -**For Options 1, 2, 4:** +**First, check if worktree is externally managed:** + +````bash +GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P) +GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P) +```` + +If `GIT_DIR` differs from `GIT_COMMON`: skip worktree removal — the host environment owns this workspace. + +**Otherwise, for Options 1 and 4:** Check if in worktree: ```bash