# Git Workflow Rule

> **Enforced on all git operations.**

---

## When Applied

- Creating branches
- Making commits
- Pushing changes
- Creating pull requests

---

## Branch Rules

### Never Push to Main
```bash
# ❌ NEVER
git push origin main

# ✅ ALWAYS
git checkout -b feature/my-feature
git push -u origin feature/my-feature
```

### Branch Naming
```
feature/add-user-auth     # New features
fix/login-redirect-loop   # Bug fixes
refactor/user-service     # Refactoring
docs/api-documentation    # Documentation
test/auth-edge-cases      # Test additions
```

---

## Commit Rules

### Atomic Commits
Each commit = ONE logical change

```bash
# ❌ BAD: Multiple concerns
git commit -m "feat: add login and fix validation and update styles"

# ✅ GOOD: Atomic commits
git commit -m "feat: add login form component"
git commit -m "fix: resolve email validation error"
git commit -m "style: update form input styling"
```

### The "AND" Test
If your message contains "and", split into multiple commits.

### Commit Message Format
```
<type>: <description>

[optional body]

[optional footer]
```

Types:
- `feat:` - New feature
- `fix:` - Bug fix
- `refactor:` - Code restructuring
- `docs:` - Documentation
- `test:` - Test additions
- `chore:` - Maintenance
- `style:` - Formatting

### Examples
```bash
# Simple commit
git commit -m "feat: add user registration endpoint"

# Commit with body
git commit -m "fix: resolve race condition in cache

The cache was being accessed without proper locking,
causing intermittent failures under high load.

Fixes #123"
```

---

## Staging Rules

### Explicit Staging Only
```bash
# ❌ NEVER
git add -A
git add .
git add --all

# ✅ ALWAYS
git add src/auth.py tests/test_auth.py
```

### Review Before Commit
```bash
git diff --cached  # Review staged changes
git status         # Verify correct files
```

---

## Pull Request Rules

### Always Use PRs
No direct commits to main/master.

### PR Checklist
- [ ] Tests pass
- [ ] Lint/format clean
- [ ] Types check
- [ ] Documentation updated
- [ ] Descriptive title and body

---

## Enforcement

Violations trigger:
1. Pre-push hook failure (if on main)
2. CI check failure
3. PR review blocker
