$npx -y skills add HLND2T/CS2_VibeSignatures --skill cleanup-workspaceClean up the local workspace after a dev branch has been merged into main. Verifies the current dev branch is fully merged into origin/main, then switches to main, pulls the latest, deletes the local dev branch, and deletes the remote dev branch if it still exists. STOPS and warn
| 1 | # Cleanup Workspace |
| 2 | |
| 3 | Post-merge housekeeping: verify the active dev branch landed in `main`, then prune it locally and on `origin`. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | After a pull request authored on a `dev*` branch has been merged into `main` and the user wants to return the workspace to a clean state on the updated `main` branch. |
| 8 | |
| 9 | ## Safety Rules |
| 10 | |
| 11 | - **NEVER** delete a branch that is not fully merged into `origin/main`. If the merge check fails, STOP immediately and report to the user — do not pass `-D` to force delete. |
| 12 | - **NEVER** run on `main` itself. If the current branch is `main`, abort with a clear message. |
| 13 | - **NEVER** discard uncommitted changes. If the working tree is dirty, abort and ask the user to commit or stash first. |
| 14 | - The remote name is assumed to be `origin`. If `origin` is not present, abort and ask the user which remote to use. |
| 15 | |
| 16 | ## Method |
| 17 | |
| 18 | ### Step 1 — Capture state and validate preconditions |
| 19 | |
| 20 | Run these checks in parallel: |
| 21 | |
| 22 | ```bash |
| 23 | git rev-parse --abbrev-ref HEAD # current branch name |
| 24 | git status --porcelain # must be empty (clean working tree) |
| 25 | git remote # must contain 'origin' |
| 26 | ``` |
| 27 | |
| 28 | Abort with a clear message if: |
| 29 | - Current branch is `main` (nothing to clean up). |
| 30 | - `git status --porcelain` is non-empty (uncommitted changes). |
| 31 | - `origin` remote does not exist. |
| 32 | |
| 33 | Save the current branch name as `DEV_BRANCH` for later steps. |
| 34 | |
| 35 | ### Step 2 — Fetch latest refs and verify merge status |
| 36 | |
| 37 | ```bash |
| 38 | git fetch origin --prune |
| 39 | ``` |
| 40 | |
| 41 | Then check whether every commit on `DEV_BRANCH` is reachable from `origin/main`: |
| 42 | |
| 43 | ```bash |
| 44 | git merge-base --is-ancestor <DEV_BRANCH> origin/main |
| 45 | ``` |
| 46 | |
| 47 | - Exit code `0` → branch is fully merged. Proceed to Step 3. |
| 48 | - Exit code `1` → branch has commits not in `origin/main`. **STOP** and report to the user: |
| 49 | - Show the unmerged commits: `git log --oneline origin/main..<DEV_BRANCH>` |
| 50 | - Tell the user the branch is not merged and the skill will not delete it. |
| 51 | - Do **not** continue to subsequent steps. |
| 52 | |
| 53 | ### Step 3 — Switch to main and pull |
| 54 | |
| 55 | ```bash |
| 56 | git checkout main |
| 57 | git pull origin main --ff-only |
| 58 | ``` |
| 59 | |
| 60 | Use `--ff-only` so the pull aborts cleanly if something unexpected happened upstream rather than creating a merge commit silently. |
| 61 | |
| 62 | ### Step 4 — Delete the local dev branch |
| 63 | |
| 64 | ```bash |
| 65 | git branch -d <DEV_BRANCH> |
| 66 | ``` |
| 67 | |
| 68 | Use lowercase `-d` (safe delete). It refuses to delete if not merged — which should not happen since Step 2 already verified the merge, but the double-check is intentional. Do **not** fall back to `-D`. |
| 69 | |
| 70 | ### Step 5 — Delete the remote dev branch if it still exists |
| 71 | |
| 72 | First check whether the remote branch is still present (the maintainer may have already deleted it after merging the PR): |
| 73 | |
| 74 | ```bash |
| 75 | git ls-remote --heads origin <DEV_BRANCH> |
| 76 | ``` |
| 77 | |
| 78 | - Output empty → remote already deleted. Skip the delete and report "remote branch already removed". |
| 79 | - Output non-empty → delete it: |
| 80 | |
| 81 | ```bash |
| 82 | git push origin --delete <DEV_BRANCH> |
| 83 | ``` |
| 84 | |
| 85 | If the push fails (permission denied, protected branch, etc.), report the error to the user — do not retry with force. |
| 86 | |
| 87 | ### Step 6 — Report final state |
| 88 | |
| 89 | Summarize what changed in a short message: |
| 90 | - Current branch (should be `main`) and its short SHA. |
| 91 | - Whether the local dev branch was deleted. |
| 92 | - Whether the remote dev branch was deleted or was already gone. |
| 93 | |
| 94 | ## Example Walk-through |
| 95 | |
| 96 | User finishes work on `dev-14156` which has been merged into `main` via PR: |
| 97 | |
| 98 | ``` |
| 99 | Step 1: HEAD=dev-14156, working tree clean, origin present. ✓ |
| 100 | Step 2: git fetch origin --prune |
| 101 | git merge-base --is-ancestor dev-14156 origin/main → 0 ✓ merged |
| 102 | Step 3: git checkout main |
| 103 | git pull origin main --ff-only → main now at <sha> |
| 104 | Step 4: git branch -d dev-14156 → deleted |
| 105 | Step 5: git ls-remote --heads origin dev-14156 → non-empty |
| 106 | git push origin --delete dev-14156 → deleted |
| 107 | Step 6: Report: on main @ <sha>; local dev-14156 deleted; remote dev-14156 deleted. |
| 108 | ``` |
| 109 | |
| 110 | ## Notes |
| 111 | |
| 112 | - The skill is a pure git workflow — no IDA Pro MCP or codebase analysis is involved. |
| 113 | - If the user wants to clean up a *different* branch than the one currently checked out, they should switch to it first; this skill only operates on `HEAD`. |
| 114 | - The skill never force-deletes (`-D`) or force-pushes. If a step refuses, that is a signal to stop and surface the situation, not to override. |