# Git Standards

> **Scope:** universal
> **Layer:** 0 (always load)
> **Keywords:** git, commit, branch, version control, collaboration
> **Load When:** always

Version control and collaboration standards for MORPH-SPEC projects

---

## Commit Messages

### Format

```
<type>(<scope>): <subject>

<body>

<footer>
```

### Types

- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation only
- `style`: Code style (formatting, no logic change)
- `refactor`: Code refactoring (no feature/fix)
- `test`: Adding/updating tests
- `chore`: Build/tool/dependency updates
- `perf`: Performance improvement

### Examples

```bash
feat(auth): add JWT refresh token rotation

Implemented automatic refresh token rotation on every token refresh
to improve security. Old tokens are invalidated immediately.

Closes #123
```

```bash
fix(api): prevent SQL injection in search endpoint

Sanitized user input before database query execution.
Added parameterized queries for all search operations.
```

---

## Branch Naming

### Format

```
<type>/<issue-number>-<short-description>
```

### Types

- `feature/` - New features
- `bugfix/` - Bug fixes
- `hotfix/` - Urgent production fixes
- `refactor/` - Code refactoring
- `docs/` - Documentation updates

### Examples

```bash
feature/123-user-authentication
bugfix/456-login-redirect
hotfix/789-payment-gateway-timeout
```

---

## Workflow

### Feature Development

```bash
# 1. Create branch from main
git checkout main
git pull origin main
git checkout -b feature/123-user-auth

# 2. Make changes, commit often
git add .
git commit -m "feat(auth): add User entity"

# 3. Push to remote
git push -u origin feature/123-user-auth

# 4. Create pull request
# 5. After approval, squash merge to main
```

### Pull Request Standards

- **Title**: Same format as commit messages
- **Description**:
  - Summary of changes
  - Related issues
  - Testing done
  - Breaking changes (if any)
- **Reviewers**: Minimum 1 approval required
- **CI/CD**: All checks must pass

---

## Best Practices

### DO

✅ Commit early and often (small, focused commits)
✅ Write descriptive commit messages
✅ Pull before push to avoid conflicts
✅ Use `.gitignore` to exclude build artifacts, secrets
✅ Tag releases (`v1.0.0`, `v1.1.0`)

### DON'T

❌ Commit secrets (API keys, passwords)
❌ Commit large binary files
❌ Force push to shared branches
❌ Commit directly to `main` (use PRs)
❌ Use generic messages ("fix", "update")

---

## .gitignore Templates

### .NET Projects

```gitignore
# Build results
bin/
obj/
*.user
*.suo

# NuGet packages
*.nupkg
packages/

# Environment files
.env
.env.local
appsettings.Development.json

# IDE
.vs/
.vscode/
.idea/
```

### Node.js Projects

```gitignore
# Dependencies
node_modules/
npm-debug.log
yarn-error.log

# Build output
dist/
.next/
out/

# Environment
.env
.env.local

# IDE
.vscode/
.idea/
```

---

*MORPH-SPEC by Polymorphism Tech*
