# Git Workflow Git branching strategy, commit conventions, and version control best practices for Changemaker Lite V2. ## Overview Changemaker Lite V2 uses Git for version control with a structured branching strategy and conventional commit messages. **Key Principles:** - Main branch always deployable - Feature branches for new work - Descriptive commit messages - Code review via pull requests - No direct commits to main ## Branch Structure ### Main Branches **`main`** - Production branch - Always deployable - Protected (no direct pushes) - Merges only via pull request - Tagged with version numbers **`v2`** - Development branch - Active development happens here - Features merge into v2 first - Tested before merging to main - Currently the primary development branch ### Feature Branches **Naming:** `feature/` ```bash # Create feature branch from v2 git checkout v2 git pull origin v2 git checkout -b feature/add-user-avatar # Make changes # ... # Push to remote git push -u origin feature/add-user-avatar ``` **Examples:** - `feature/add-user-avatar` - `feature/email-queue-monitoring` - `feature/map-clustering` - `feature/campaign-analytics` ### Bugfix Branches **Naming:** `fix/` ```bash # Create bugfix branch git checkout v2 git pull origin v2 git checkout -b fix/login-redirect-loop # Fix bug # ... # Push to remote git push -u origin fix/login-redirect-loop ``` **Examples:** - `fix/login-redirect-loop` - `fix/map-marker-position` - `fix/email-template-rendering` ### Hotfix Branches **Naming:** `hotfix/` For urgent production fixes: ```bash # Create from main (production) git checkout main git pull origin main git checkout -b hotfix/security-patch # Fix issue # ... # Merge to main AND v2 git checkout main git merge hotfix/security-patch git push origin main git checkout v2 git merge hotfix/security-patch git push origin v2 ``` **Examples:** - `hotfix/security-patch` - `hotfix/critical-database-error` ### Release Branches **Naming:** `release/vX.Y.Z` For preparing releases: ```bash # Create release branch from v2 git checkout v2 git pull origin v2 git checkout -b release/v2.1.0 # Prepare release (update version, changelog) # Test thoroughly # ... # Merge to main (after approval) git checkout main git merge release/v2.1.0 git tag v2.1.0 git push origin main --tags # Merge back to v2 git checkout v2 git merge release/v2.1.0 git push origin v2 ``` ## Feature Development Workflow ### Step 1: Create Branch ```bash # Update v2 branch git checkout v2 git pull origin v2 # Create feature branch git checkout -b feature/add-user-avatar # Verify branch git branch --show-current # Output: feature/add-user-avatar ``` ### Step 2: Make Changes Edit files, test locally: ```bash # Make changes vi api/src/modules/users/users.service.ts vi admin/src/pages/UsersPage.tsx # Test locally npm run dev # Type-check npm run type-check # Lint npm run lint:fix ``` ### Step 3: Stage and Commit ```bash # Check status git status # Stage specific files (NOT git add .) git add api/src/modules/users/users.service.ts git add admin/src/pages/UsersPage.tsx # Commit with conventional message git commit -m "feat(users): add avatar upload functionality Implements avatar upload with image validation and S3 storage. Adds avatar field to User model and updates UI. Closes #123" ``` ### Step 4: Push to Remote ```bash # Push branch (first time) git push -u origin feature/add-user-avatar # Push subsequent commits git push ``` ### Step 5: Create Pull Request On GitHub/GitLab: 1. Navigate to repository 2. Click "New Pull Request" 3. Select base: `v2`, compare: `feature/add-user-avatar` 4. Fill in PR template (title, description, testing steps) 5. Request reviewers 6. Link related issues ### Step 6: Address Review Feedback ```bash # Make requested changes vi api/src/modules/users/users.service.ts # Stage and commit git add api/src/modules/users/users.service.ts git commit -m "fix(users): address review feedback - Add error handling for upload failures - Improve validation messages - Add JSDoc comments" # Push changes git push ``` ### Step 7: Merge (After Approval) **Squash and Merge** (recommended): - Combines all commits into one - Clean history on v2 branch - Preserves individual commits in branch **Merge Commit:** - Preserves all commits - More detailed history - Use for large features **Rebase and Merge:** - Linear history - No merge commits - Use when v2 has diverged ### Step 8: Clean Up ```bash # Delete local branch git checkout v2 git branch -d feature/add-user-avatar # Delete remote branch (if not auto-deleted) git push origin --delete feature/add-user-avatar # Update v2 git pull origin v2 ``` ## Commit Messages ### Conventional Commits Format ``` ():