For setting up branch protection on new repositories, see create-branch-protections.prompt.md
- ALL development happens on
testingbranch - NEVER commit directly to
mainbranch - ONLY merge to
mainafter testing and approval - ALWAYS switch back to
testingafter merging
# Always work on testing
git checkout testing
# Make changes, commit, test
git add .
git commit -m "your message"
# When ready to promote to main
git checkout main
git merge testing
git checkout testing # Switch back immediately!# No changes made yet? Just switch back:
git checkout testing
# Made changes? Stash and move them:
git stash
git checkout testing
git stash popIf you see:
❌ ERROR: Direct commits to 'main' branch are not allowed!
Solution:
git checkout testing # Switch to testing branch# Run branch protection check
import subprocess
result = subprocess.run(
["python", ".agents/branch_protection.py"],
capture_output=True
)
if result.returncode != 0:
# STOP - Cannot modify files
print(result.stdout.decode())
exit(1)AI can help with merges ONLY when human explicitly says:
- "help me merge testing to main"
- "assist with the merge"
- "I want to merge now"
Never suggest or perform file modifications on main.
| Component | Protects Against | When Active |
|---|---|---|
pre-commit hook |
Direct commits to main | Every commit attempt |
post-checkout hook |
Forgetting you're on main | After branch switch |
post-merge hook |
Staying on main after merge | After merge completes |
branch_protection.py |
AI modifications to main | Before AI file operations |
memory.instruction.md |
AI violations | Every AI session |
# Test 1: Try to commit to main (should fail)
git checkout main
touch test.txt
git add test.txt
git commit -m "test" # ❌ Will be blocked
# Test 2: Switch to main (should warn)
git checkout main # ⚠️ Will display warning
# Test 3: AI protection script
git checkout main
python .agents/branch_protection.py # ❌ Exit code 1
git checkout testing
python .agents/branch_protection.py # ✅ Exit code 0Only use in genuine emergencies:
# Disable pre-commit hook temporarily
git commit --no-verify
# Or rename hook
mv .git/hooks/pre-commit .git/hooks/pre-commit.disabled
# ... do emergency work ...
mv .git/hooks/pre-commit.disabled .git/hooks/pre-commit✅ testing = development, commits, changes, testing ❌ main = merges only, read-only otherwise
Remember: After every merge to main, immediately return to testing!