$npx -y skills add ancoleman/ai-design-components --skill managing-git-workflowsManage Git branching strategies, commit conventions, and collaboration workflows. Use when choosing between trunk-based development, GitHub Flow, or GitFlow, implementing conventional commits for automated versioning, setting up Git hooks for quality gates, or organizing monorepo
| 1 | # Git Workflows |
| 2 | |
| 3 | Implement structured Git workflows for team collaboration, code quality, and automated releases. This skill covers branching strategies, conventional commit formats, Git hooks, and monorepo management patterns. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Choosing a branching strategy for a new project or team |
| 9 | - Implementing consistent commit message formats |
| 10 | - Setting up Git hooks for linting, testing, or validation |
| 11 | - Managing monorepos with multiple projects |
| 12 | - Establishing code review workflows |
| 13 | - Automating versioning and releases |
| 14 | |
| 15 | ## Quick Decision: Which Branching Strategy? |
| 16 | |
| 17 | ### Trunk-Based Development |
| 18 | Use when the team has strong CI/CD automation, comprehensive test coverage (80%+), and deploys frequently (daily or more). Short-lived branches merge within 1 day. Requires feature flags for incomplete features. |
| 19 | |
| 20 | **Best for:** High-velocity teams with mature DevOps practices (Google, Facebook, Netflix) |
| 21 | |
| 22 | ### GitHub Flow |
| 23 | Use for web applications with continuous deployment. Main branch always represents production. Simple PR-based workflow for small to medium teams (2-20 developers). |
| 24 | |
| 25 | **Best for:** Startups, SaaS products, open-source projects |
| 26 | |
| 27 | ### GitFlow |
| 28 | Use when supporting multiple production versions simultaneously, requiring formal QA cycles, or following scheduled releases (monthly, quarterly). More complex but structured. |
| 29 | |
| 30 | **Best for:** Enterprise software, mobile apps with App Store releases, on-premise products |
| 31 | |
| 32 | For detailed branching patterns with examples, see `references/branching-strategies.md`. |
| 33 | |
| 34 | ## Conventional Commits |
| 35 | |
| 36 | Structure commit messages for automated versioning and changelog generation: |
| 37 | |
| 38 | ``` |
| 39 | <type>[optional scope]: <description> |
| 40 | |
| 41 | [optional body] |
| 42 | |
| 43 | [optional footer(s)] |
| 44 | ``` |
| 45 | |
| 46 | **Common Types:** |
| 47 | - `feat` - New feature (MINOR version bump: 0.1.0) |
| 48 | - `fix` - Bug fix (PATCH version bump: 0.0.1) |
| 49 | - `docs` - Documentation only |
| 50 | - `refactor` - Code restructuring without feature change |
| 51 | - `test` - Adding or updating tests |
| 52 | - `chore` - Maintenance tasks |
| 53 | |
| 54 | **Breaking Changes:** |
| 55 | - Add `!` after type: `feat!:` or `fix!:` |
| 56 | - Add `BREAKING CHANGE:` in footer |
| 57 | - Results in MAJOR version bump (1.0.0) |
| 58 | |
| 59 | **Examples:** |
| 60 | ```bash |
| 61 | git commit -m "feat(auth): add JWT token validation" |
| 62 | git commit -m "fix: resolve race condition in user login" |
| 63 | git commit -m "feat!: redesign authentication API |
| 64 | |
| 65 | BREAKING CHANGE: Auth endpoints now require API version header" |
| 66 | ``` |
| 67 | |
| 68 | For complete specification and tooling setup, see `references/conventional-commits.md`. |
| 69 | |
| 70 | ## Git Hooks for Quality Gates |
| 71 | |
| 72 | Automate code quality checks at key workflow points: |
| 73 | |
| 74 | **pre-commit** - Run before commit is created |
| 75 | - Linting (ESLint, Prettier) |
| 76 | - Formatting checks |
| 77 | - Quick tests |
| 78 | |
| 79 | **commit-msg** - Validate commit message format |
| 80 | - Enforce conventional commits |
| 81 | - Check message length |
| 82 | |
| 83 | **pre-push** - Run before pushing to remote |
| 84 | - Full test suite |
| 85 | - Prevent force push to protected branches |
| 86 | |
| 87 | **Quick Setup with Husky:** |
| 88 | ```bash |
| 89 | npm install --save-dev husky lint-staged @commitlint/cli @commitlint/config-conventional |
| 90 | npx husky init |
| 91 | npx husky add .husky/pre-commit "npx lint-staged" |
| 92 | npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1' |
| 93 | ``` |
| 94 | |
| 95 | For complete hook configuration and examples, see `references/git-hooks-guide.md`. |
| 96 | |
| 97 | ## Monorepo Management |
| 98 | |
| 99 | ### Build Tool Selection |
| 100 | |
| 101 | **Nx** - Best for TypeScript/JavaScript monorepos |
| 102 | - Dependency graph analysis |
| 103 | - Affected commands (only rebuild changed projects) |
| 104 | - Distributed caching |
| 105 | |
| 106 | **Turborepo** - Best for Next.js/React applications |
| 107 | - Fast incremental builds |
| 108 | - Remote caching |
| 109 | - Simple configuration |
| 110 | |
| 111 | **Sparse Checkout** - For large repos when full clone not needed |
| 112 | ```bash |
| 113 | git sparse-checkout init --cone |
| 114 | git sparse-checkout set apps/web libs/ui-components |
| 115 | ``` |
| 116 | |
| 117 | ### Code Ownership |
| 118 | |
| 119 | Use `.github/CODEOWNERS` to define ownership: |
| 120 | ``` |
| 121 | # Default owners |
| 122 | * @org/engineering |
| 123 | |
| 124 | # Apps ownership |
| 125 | /apps/web/ @org/web-team |
| 126 | /apps/mobile/ @org/mobile-team |
| 127 | |
| 128 | # Security-critical |
| 129 | /libs/auth/ @org/security-team @org/principal-engineers |
| 130 | ``` |
| 131 | |
| 132 | For detailed monorepo patterns, see `references/monorepo-patterns.md`. |
| 133 | |
| 134 | ## Merge vs Rebase |
| 135 | |
| 136 | ### Merge Commits |
| 137 | Use when preserving complete history is important: |
| 138 | ```bash |
| 139 | git checkout main |
| 140 | git merge feature-branch |
| 141 | ``` |
| 142 | **When:** Multiple developers on feature branch, want to see integration point |
| 143 | |
| 144 | ### Squash and Merge |
| 145 | Use for clean, linear history: |
| 146 | ```bash |
| 147 | git checkout main |
| 148 | git merge --squash feature-branch |
| 149 | git commit -m "feat: add user authentication" |
| 150 | ``` |
| 151 | **When:** Feature has many WIP commits, want clean main branch history |
| 152 | |
| 153 | ### Rebase |
| 154 | Use for linear history without merge commits: |
| 155 | ```bash |
| 156 | git checkout feature-branch |
| 157 | git rebase main |
| 158 | ``` |
| 159 | **When:** |