--- name: git-workflow description: "Git workflow management with atomic commit principles. Capabilities: commit organization, branching strategies, merge/rebase workflows, PR management, history cleanup, staged change analysis, single-responsibility commits. Actions: commit, push, pull, merge, rebase, branch, stage, stash git operations. Keywords: git commit, git push, git pull, git merge, git rebase, git branch, git stash, atomic commit, commit message, conventional commits, branching strategy, GitFlow, trunk-based, PR, pull request, code review, git history, cherry-pick, squash, amend, interactive rebase, staged changes. Use when: organizing commits, creating branches, merging code, rebasing, writing commit messages, managing PRs, cleaning git history, analyzing staged changes." --- # Git Workflow & Best Practices ## Purpose Comprehensive guide for git operations with emphasis on clean history, atomic commits, and professional workflows. Automatically analyzes staged changes and enforces single-responsibility principle. ## When to Use Activate for any git operation: - Committing changes (especially multiple files) - Creating branches - Merging or rebasing - Managing git history - Writing commit messages - Organizing staging area - Code review preparation - Repository management ## Core Philosophy ### Single Responsibility Rule ⭐ **CRITICAL:** Before committing, analyze staged changes and divide into atomic commits. **Process:** 1. Run `git status` to see all staged files 2. Identify different concerns/features 3. Unstage everything: `git reset HEAD` 4. Stage files by concern, one group at a time 5. Commit each group with focused message 6. Repeat until all changes are committed **Why:** Makes history reviewable, revertable, and maintainable. --- ## Commit Organization ### Analyzing Staged Changes ```bash # Check what's staged git status # See file-level summary git diff --cached --stat # See detailed changes git diff --cached # Check specific file git diff --cached path/to/file ``` ### Grouping Strategies **By Feature:** - Auth system changes → one commit - Payment module → separate commit - User profile → another commit **By Layer:** - Database migrations → first commit - Backend API → second commit - Frontend UI → third commit - Tests → fourth commit **By Type:** - New features (feat) - Bug fixes (fix) - Refactoring (refactor) - Documentation (docs) - Performance (perf) - Tests (test) **By Dependency:** - Foundation/infrastructure first - Features that depend on foundation second ### Division Workflow ```bash # 1. Analyze current state git status git diff --cached --stat # 2. Unstage everything git reset HEAD # 3. Stage first logical group git add file1.ts file2.ts directory/ # 4. Verify what's staged git diff --cached --stat # 5. Commit with focused message git commit -m "type: concise description" # 6. Repeat steps 3-5 for remaining groups ``` ### Example: Real Scenario **Situation:** 29 files staged with mixed concerns ```bash # Before - messy staging $ git status Changes to be committed: # Trading Styles feature (25 files) modified: src/app/styles/page.tsx new file: src/core/domain/models/TradingStyle.ts new file: src/infrastructure/database/migrations/create_trading_styles.ts ... # History enhancements (4 files) modified: src/app/history/page.tsx modified: src/app/api/history/recommendations/route.ts ... ``` **Solution:** ```bash # 1. Reset staging git reset HEAD # 2. Commit #1 - Trading Styles feature git add \ package.json pnpm-lock.yaml \ src/app/styles/ \ src/core/domain/models/TradingStyle.ts \ src/core/ports/ITradingStyleRepository.ts \ src/infrastructure/database/TradingStyleRepository.ts \ src/infrastructure/database/migrations/create_trading_styles.ts git commit -m "feat: Add trading style persona system for AI-powered analysis" # 3. Commit #2 - History enhancements git add \ src/app/history/page.tsx \ src/app/api/history/recommendations/route.ts \ src/infrastructure/database/TimeseriesRepository.ts \ src/components/layout/AppLayout.tsx git commit -m "feat: Add comprehensive search and filtering to history page" ``` **Result:** Clean, focused commits that are independently reviewable and revertable. --- ## Commit Messages ### Conventional Commits Format ``` ():