Git Safety Skill
Apply rigorous git safety protocols to prevent data loss and conflicts in collaborative development environments, particularly when multiple agents or developers work concurrently.
Core Safety Principles
File Management Rules
Deleting Files:
- ⚠️ STOP before deleting any file to resolve type/lint failures - Ask the user first
- Only remove obsolete files when changes make them genuinely irrelevant
- Only revert your own work or changes explicitly requested by the user
- Coordinate with teammates before removing in-progress edits
- Never assume a file is safe to delete without confirmation
File Modifications:
- Always verify file ownership and recent changes before modifying
- Check
git log <file>to see who last edited - Communicate before making sweeping changes to shared files
Environment & Configuration Safety
Critical: Environment Files
- 🚫 NEVER edit
.envor any environment variable files - Only the user may change environment configurations
- This includes
.env,.env.local,.env.production, etc. - If environment changes are needed, inform the user - never make them yourself
Git Configuration:
- Never modify
.gitconfigor repository git settings - Never amend commits without explicit written approval
- Preserve existing git hooks and configurations
Destructive Operations - Extreme Caution Required
Absolutely Forbidden Without Explicit Permission
🚨 ABSOLUTELY NEVER run these operations unless the user gives explicit, written instruction:
git reset --hard- Destroys uncommitted work permanentlygit checkout <old-commit>- Can lose current workgit restore --source=<old-commit>- Reverts to old state, losing changesrm -rf- Irreversible file deletiongit push --force- Overwrites remote historygit rebasewithout safeguards - Can lose commitsgit clean -fd- Deletes untracked files permanently
What Requires User Approval
Before running these commands, STOP and ask the user explicitly:
- Any command that can lose uncommitted changes
- Force pushing to remote repositories
- Rebasing published branches
- Amending pushed commits
- Deleting branches (local or remote)
- Hard resets of any kind
- File deletions to fix build errors
Safe Workflow Standards
Before Any Commit
Pre-commit Checklist:
- Run
git statusto verify exactly what's being committed - Use explicit file paths - never
git add .orgit add -Ablindly - Ensure only modified/intended files are staged
- Review diffs with
git diff --staged - Keep commits atomic (focused on one logical change)
Example - Safe Commit:
# Good: Explicit, verified, atomic
git status
git add src/components/Button.tsx src/components/Button.test.tsx
git diff --staged
git commit -m "feat: add disabled state to Button component"
Example - Unsafe Commit:
# Bad: No verification, adds everything
git add .
git commit -m "fixes"
Path Handling
Quote Special Characters:
- Always quote paths with brackets, parentheses, or spaces
- Use double quotes to prevent shell interpretation
# Good
git add "src/utils/parse(data).ts"
git add "src/components/[id].tsx"
# Bad - shell may misinterpret
git add src/utils/parse(data).ts
git add src/components/[id].tsx
Rebase Safety
When rebasing is necessary:
# Suppress editor prompts
GIT_SEQUENCE_EDITOR=true git rebase <branch>
# Or set environment variable
export GIT_SEQUENCE_EDITOR=true
git rebase main
Coordination in Collaborative Environments
Before Major Changes
Communication First:
- Check who else is working on related files:
git log --since="1 day ago" --oneline - Announce intention to make sweeping changes
- Wait for confirmation before proceeding
- Coordinate timing of force pushes or rebases
Conflict Prevention
Proactive Coordination:
- Pull frequently:
git pull --rebase - Communicate when working on shared files
- Use feature branches to isolate work
- Merge main frequently to stay current
Decision Tree for Destructive Operations
Are you about to run a destructive git command?
├─ YES → Is there explicit written user approval?
│ ├─ YES → Proceed carefully, verify twice
│ └─ NO → STOP. Ask user for permission first.
└─ NO → Proceed with normal safety checks
Common Scenarios
Scenario 1: Type Error in File
Wrong Approach:
# ❌ Delete file to fix error
rm src/components/BrokenComponent.tsx
Right Approach:
# ✅ Stop and ask user
# "I see a type error in BrokenComponent.tsx.
# Should I fix the error or is this file obsolete?"
Scenario 2: Need to Reset Changes
Wrong Approach:
# ❌ Hard reset without asking
git reset --hard HEAD
Right Approach:
# ✅ Ask first, then use safer methods
git stash # Preserves work
# OR
git checkout -b backup-branch # Creates backup
Scenario 3: Multiple Agents Working
Wrong Approach:
# ❌ Force push over teammate's work
git push --force
Right Approach:
# ✅ Coordinate first
# "I need to force push to fix history.
# Is anyone else working on this branch?"
Safety Verification Commands
Before Destructive Operations:
# Check what will be affected
git status
git log --oneline -n 10
git diff HEAD
# See who's been working recently
git log --since="1 day ago" --all --oneline
# Check remote status
git fetch
git status
Environment File Protection
Files to NEVER modify:
.env.env.local.env.development.env.production.env.test- Any file matching
.env.*
If environment changes are needed:
- Stop immediately
- Inform the user exactly what needs to change
- Let the user make the modification
- Never assume or guess environment values
Summary - The Golden Rules
- 🛑 STOP before deleting files to fix build errors
- 🚫 NEVER touch environment files - user only
- ⚠️ Get explicit permission for destructive git operations
- ✅ Verify with git status before every commit
- 📝 Use explicit paths - never blindly add all files
- 🔒 Quote special characters in file paths
- 🤝 Coordinate with teammates before major changes
- 💾 When in doubt, ask - communication over assumption
When This Skill Applies
Invoke this skill when:
- About to run any git command
- Considering deleting a file
- Planning to modify shared files
- Encountering build/type errors that might be "fixed" by deletion
- Working in an environment where others might be active
- Unsure if an operation is safe
Default stance: Cautious and communicative. Preserve work, ask questions, coordinate changes.