Git Conventions
Module 10.2: Git Conventions
Section titled “Module 10.2: Git Conventions”Estimated time: ~30 minutes
Prerequisite: Module 10.1 (Team CLAUDE.md)
Outcome: After this module, you will have git conventions that work for AI-assisted development, know how to train Claude to follow them, and understand best practices for commit attribution.
1. WHY — Why This Matters
Section titled “1. WHY — Why This Matters”Developer uses Claude Code to implement a feature. Claude makes 1 giant commit with message “implemented feature.” PR reviewer can’t understand what changed or why. Another developer’s Claude commits are verbose novels. Git history is useless for debugging.
Git conventions exist for humans. When AI generates commits, those conventions matter MORE — because AI will consistently follow them (or consistently ignore them). This module makes Claude a good git citizen.
2. CONCEPT — Core Ideas
Section titled “2. CONCEPT — Core Ideas”Commit Message Convention
Section titled “Commit Message Convention”<type>(<scope>): <short description>
[optional body: what and why]
🤖 Generated with Claude CodeTypes: feat, fix, refactor, docs, test, chore
Commit Granularity Rules
Section titled “Commit Granularity Rules”| Rule | Good | Bad |
|---|---|---|
| Atomic commits | One logical change per commit | ”implemented everything” |
| Reviewable size | 50-200 lines per commit | 2000-line commit |
| Builds pass | Each commit compiles/passes tests | Broken intermediate commits |
Branch Naming
Section titled “Branch Naming”<type>/<ticket>-<short-description>
feat/PROJ-123-user-authfix/PROJ-456-login-validationrefactor/PROJ-789-payment-serviceAI Attribution Approaches
Section titled “AI Attribution Approaches”- Footer marker:
🤖 AI-assistedin commit message (recommended) - Co-author:
Co-authored-by: Claude <noreply@anthropic.com> - Branch suffix:
-ai-assisted - PR label: Add “AI-assisted” label
Footer marker is least intrusive, most informative.
3. DEMO — Step by Step
Section titled “3. DEMO — Step by Step”Scenario: Team adopts Conventional Commits with AI attribution.
Step 1: Add Git Conventions to CLAUDE.md
Section titled “Step 1: Add Git Conventions to CLAUDE.md”## Git Conventions
### Commit Message Format<type>(<scope>): <short description>
[body: explain what and why, not how]
🤖 Generated with Claude Code
### Types- feat: New feature- fix: Bug fix- refactor: Code change that neither fixes nor adds- docs: Documentation only- test: Adding tests- chore: Maintenance
### Rules- Subject line: max 50 characters, imperative mood- Body: wrap at 72 characters- One logical change per commit- Each commit must pass: npm test && npm run lintStep 2: Train Claude with Example
Section titled “Step 2: Train Claude with Example”You: I've added git conventions to CLAUDE.md. Let's practice.I just added input validation to the login form.Generate the appropriate commit.
Claude: Here's the commit following our conventions:
git commit -m "feat(auth): add input validation to login form
Add email format validationAdd password strength requirementsDisplay inline error messages
🤖 Generated with Claude Code"Step 3: Multi-Commit Workflow
Section titled “Step 3: Multi-Commit Workflow”You: Implement user registration with email verification.Break this into appropriate commits following our granularity rules.
Claude: I'll implement this in 4 atomic commits:1. feat(auth): add user registration endpoint2. feat(auth): add email verification token generation3. feat(auth): add verification email sending4. feat(auth): add email verification confirmation endpoint
Each commit will be independently testable. Shall I proceed?Step 4: Verify in Git Log
Section titled “Step 4: Verify in Git Log”$ git log --oneline -5Output:
abc1234 feat(auth): add email verification confirmation endpointdef5678 feat(auth): add verification email sendingghi9012 feat(auth): add email verification token generationjkl3456 feat(auth): add user registration endpointmno7890 docs: update CLAUDE.md with git conventions4. PRACTICE — Try It Yourself
Section titled “4. PRACTICE — Try It Yourself”Exercise 1: Convention Setup
Section titled “Exercise 1: Convention Setup”Goal: Configure git conventions for your team.
Instructions:
- Add git convention section to your CLAUDE.md
- Include: message format, types, granularity rules
- Include AI attribution approach
- Test with a small change
💡 Hint
## Git Conventions- Format: type(scope): description- Types: feat, fix, refactor, docs, test, chore- Max 50 char subject line- Add 🤖 AI-assisted footerExercise 2: Atomic Commit Drill
Section titled “Exercise 2: Atomic Commit Drill”Goal: Practice proper commit granularity.
Instructions:
- Ask Claude to implement a medium feature
- Require it to break into 3-5 atomic commits
- Review each commit: Is it truly atomic? Does it pass tests alone?
- Iterate on CLAUDE.md if Claude’s granularity is off
Exercise 3: History Readability
Section titled “Exercise 3: History Readability”Goal: Validate your conventions work.
Instructions:
- After using Claude for a day, run
git log --oneline -20 - Can you understand what happened from messages alone?
- If not, what’s missing? Update CLAUDE.md.
✅ Solution
Good git log output:
abc1234 feat(cart): add quantity validationdef5678 fix(cart): handle empty cart checkoutghi9012 refactor(cart): extract price calculationjkl3456 test(cart): add unit tests for CartServiceBad git log output:
abc1234 updatesdef5678 WIPghi9012 fixed stuffjkl3456 implemented featureIf your log looks like the bad example, add more specific rules to CLAUDE.md.
5. CHEAT SHEET
Section titled “5. CHEAT SHEET”Commit Message Format
Section titled “Commit Message Format”<type>(<scope>): <description>
[body]
🤖 Generated with Claude Codefeat | fix | refactor | docs | test | chore
Granularity Rules
Section titled “Granularity Rules”- One logical change per commit
- 50-200 lines per commit
- Each commit passes tests
Branch Naming
Section titled “Branch Naming”<type>/<ticket>-<description>feat/PROJ-123-user-authCLAUDE.md Git Section
Section titled “CLAUDE.md Git Section”## Git Conventions- Format: type(scope): description- Max 50 char subject- Add 🤖 AI-assisted footer- Atomic commits, each passes testsQuick Prompts
Section titled “Quick Prompts”- “Commit this following our conventions”
- “Break this into atomic commits”
- “What’s the appropriate commit type?“
6. PITFALLS — Common Mistakes
Section titled “6. PITFALLS — Common Mistakes”| ❌ Mistake | ✅ Correct Approach |
|---|---|
| ”Just commit it” with no format | Explicit format in CLAUDE.md |
| Giant commits (“implemented feature”) | Require atomic commits |
| No AI attribution | Footer marker: 🤖 AI-assisted |
| Committing broken code | Rule: each commit must pass tests |
| Vague commit messages | Require body explaining why |
| Inconsistent between team members | Same CLAUDE.md = same conventions |
| Obsessing over perfect commits | Good enough is fine. Squash in PR if needed. |
7. REAL CASE — Production Story
Section titled “7. REAL CASE — Production Story”Scenario: Vietnamese dev team, 8 developers, heavy Claude Code usage. Git history became unusable:
- “fixed stuff”
- “WIP”
- 500-line commits with no description
- No way to understand feature evolution
Solution: Git conventions in CLAUDE.md
Added:
- Conventional Commits format
- 🤖 footer for AI-generated code
- Atomic commit requirement
- Pre-commit hook: rejects commits without proper format
Results after 2 weeks:
git logbecame readable- Code review time: -30% (reviewers understood commit intent)
- Debugging easier (could bisect with meaningful commits)
- New devs understood feature history without asking
Unexpected benefit: AI attribution helped identify patterns — “AI-generated commits have fewer bugs but sometimes miss edge cases” became a learning for the team.