$npx -y skills add Svenja-dev/claude-code-skills --skill safe-git-guardPrevents destructive Git operations by requiring backup and confirmation. Blocks git reset --hard, git push --force on main, git clean -fd. Requires backup before git checkout, git reset, git rebase. Activate on any destructive git command.
| 1 | # Safe Git Guard |
| 2 | |
| 3 | > Skill to prevent destructive Git operations |
| 4 | |
| 5 | ## Trigger |
| 6 | |
| 7 | This skill activates automatically on these commands: |
| 8 | |
| 9 | - `git reset --hard` |
| 10 | - `git checkout -- <file>` |
| 11 | - `git clean -fd` |
| 12 | - `git rebase` (without explicit confirmation) |
| 13 | - `git push --force` |
| 14 | |
| 15 | ## Rules |
| 16 | |
| 17 | ### FORBIDDEN (never execute): |
| 18 | |
| 19 | 1. **`git reset --hard`** - Deletes uncommitted changes irreversibly |
| 20 | 2. **`git push --force` on main/master** - Can destroy remote history |
| 21 | 3. **`git clean -fd`** - Deletes untracked files irreversibly |
| 22 | |
| 23 | ### WARNING + BACKUP required: |
| 24 | |
| 25 | 1. **`git checkout -- <file>`** - Overwrites local changes |
| 26 | - BEFORE execution: Create backup |
| 27 | - `git stash push -m "backup-before-checkout-$(date +%s)"` |
| 28 | |
| 29 | 2. **`git reset HEAD~n`** - Resets commits |
| 30 | - BEFORE execution: Create tag |
| 31 | - `git tag backup-before-reset-$(date +%s)` |
| 32 | |
| 33 | 3. **`git rebase`** - Modifies history |
| 34 | - BEFORE execution: Create backup branch |
| 35 | - `git branch backup-before-rebase-$(date +%s)` |
| 36 | |
| 37 | ## Workflow for Destructive Operations |
| 38 | |
| 39 | ``` |
| 40 | 1. STOP - Don't execute immediately |
| 41 | 2. BACKUP - Save current state (tag/branch/stash) |
| 42 | 3. ASK - "Are you sure? What will be lost?" |
| 43 | 4. CONFIRM - Explicit "Yes, I understand the risk" |
| 44 | 5. EXECUTE - Only then run the command |
| 45 | ``` |
| 46 | |
| 47 | ## Example Dialog |
| 48 | |
| 49 | **User:** "Undo the last 3 commits" |
| 50 | |
| 51 | **Claude (with this skill):** |
| 52 | |
| 53 | ``` |
| 54 | WARNING: DESTRUCTIVE OPERATION DETECTED |
| 55 | |
| 56 | You want to run `git reset HEAD~3`. This would: |
| 57 | - Remove 3 commits from history |
| 58 | - Changes become "unstaged" (--soft) or deleted (--hard) |
| 59 | |
| 60 | Creating backup: |
| 61 | > git tag backup-YYYYMMDD-pre-reset |
| 62 | |
| 63 | Should I proceed? (Answer with "Yes, proceed with reset") |
| 64 | ``` |
| 65 | |
| 66 | ## Protected Branches |
| 67 | |
| 68 | Configure in your project's CLAUDE.md: |
| 69 | |
| 70 | ```yaml |
| 71 | protected_branches: |
| 72 | - main # Production branch, never force-push |
| 73 | - master # Legacy production branch |
| 74 | - develop # Development branch, PR only |
| 75 | - release/* # Release branches, approval only |
| 76 | ``` |
| 77 | |
| 78 | ## Integration with No-Touch Zones |
| 79 | |
| 80 | This skill respects No-Touch Zones defined in CLAUDE.md. |
| 81 | When changes affect protected files: Additional warning + Impact Analysis. |
| 82 | |
| 83 | ## Configuration |
| 84 | |
| 85 | Add to your CLAUDE.md: |
| 86 | |
| 87 | ```markdown |
| 88 | ### Git Safety Rules |
| 89 | |
| 90 | Protected Branches: |
| 91 | - main, develop, release/* |
| 92 | |
| 93 | No-Touch Zones (require explicit approval): |
| 94 | - src/auth/** |
| 95 | - src/core/** |
| 96 | - config/production.* |
| 97 | ``` |
| 98 | |
| 99 | --- |
| 100 | |
| 101 | ## Origin |
| 102 | |
| 103 | Originally developed for [fabrikIQ](https://fabrikiq.com) - AI-powered manufacturing data analysis. |
| 104 | |
| 105 | ## License |
| 106 | |
| 107 | MIT - Free to use and modify |