Git Commit Message Prompt Template
Why This Template
Writing good commit messages is hard. This template helps you get consistent, professional messages using AI with built-in code quality and security analysis.
Quick Setup
Add these aliases to your shell configuration (~/.bashrc or ~/.zshrc):
1. aicommit - Commit Message Generator with Issue Scanning
alias aicommit="gemini --yolo -p 'Analyze my git repository changes and generate 5 commit message recommendations WITH comprehensive issue review:
Instructions:
1. Run git status to detect new and modified files
2. Run git diff to understand what changed in modified files
3. For new files, only read them if they are critical to understanding the overall change
4. Prioritize analyzing modifications over new file contents
5. Perform SonarQube-style code quality and security analysis
6. Generate 5 commit messages in numbered list format
7. Skip git log --oneline -5
Requirements:
- Use conventional commit format (feat/fix/refactor/test/docs/chore)
- Focus primarily on what was modified and why
- Emphasize the nature of changes in existing code
- Consider modified files as the primary source of truth for the change intent
- Return as numbered list only
Format each message as:
type(scope): brief description
Analysis should prioritize:
- What existing functionality was changed and how
- Why the modifications were made (bug fix, refactor, enhancement)
- The impact of changes on existing behavior
- Secondary consideration for new files only if they are essential context
ISSUE SCANNING (SonarQube-style):
🔴 BLOCKER (Must fix before commit):
- Security hotspots (hardcoded credentials, SQL injection, XSS, CSRF)
- Critical bugs (null pointer, unhandled exceptions, resource leaks)
- Data corruption risks
🟠 CRITICAL (Should fix before commit):
- Major security vulnerabilities (weak crypto, auth issues)
- Breaking API changes without versioning
- Memory leaks, deadlocks
- Missing error handling in critical paths
🟡 MAJOR (Review recommended):
- Code smells (high complexity, duplicate code >10 lines)
- Performance issues (N+1 queries, inefficient algorithms)
- Maintainability issues (god classes, long methods >50 lines)
- Missing tests for new logic
- TODO/FIXME comments in production code
🔵 MINOR (Nice to fix):
- Convention violations (naming, formatting)
- Missing documentation
- Unused imports/variables
- Magic numbers without constants
Output Format:
1. Issue Summary Section:
- \"⚠️ [SEVERITY] ISSUES DETECTED\" or \"✓ No critical issues detected\"
- List issues by severity with file:line location
- Include SonarQube-like quality gate status (PASSED/FAILED)
2. Commit Messages Section:
- If blocker issues: Prefix messages with \"⚠️ BLOCKED: \"
- If critical issues: Prefix with \"⚠️ REVIEW REQUIRED: \"
- If only minor issues: Proceed with normal messages
- Provide 5 conventional commit messages'"
2. aibranch - Branch Name & Commit Message Generator
alias aibranch="gemini --yolo -p 'Analyze my git repository changes and generate 5 branch recommendations and corresponding commit messages WITH comprehensive issue review:
Instructions:
1. Run git status to detect new and modified files
2. Run git diff to understand what changed in modified files
3. For new files, only read them if they are critical to understanding the overall change
4. Prioritize analyzing modifications over new file contents
5. Perform SonarQube-style code quality and security analysis
6. Generate 5 branch recommendations in numbered list format
7. Provide 5 matching commit message recommendations for the changes
8. Skip git log --oneline -5
Requirements:
- Use conventional branch naming (feature/fix/refactor/hotfix/chore)
- Use conventional commit format (feat/fix/refactor/test/docs/chore)
- Focus primarily on what was modified and why
- Emphasize the nature of changes in existing code
- Consider modified files as the primary source of truth for the change intent
ISSUE SCANNING (SonarQube-style):
🔴 BLOCKER (Must fix before commit):
- Security hotspots (hardcoded credentials, SQL injection, XSS, CSRF)
- Critical bugs (null pointer, unhandled exceptions, resource leaks)
- Data corruption risks
🟠 CRITICAL (Should fix before commit):
- Major security vulnerabilities (weak crypto, auth issues)
- Breaking API changes without versioning
- Memory leaks, deadlocks
- Missing error handling in critical paths
🟡 MAJOR (Review recommended):
- Code smells (high complexity, duplicate code >10 lines)
- Performance issues (N+1 queries, inefficient algorithms)
- Maintainability issues (god classes, long methods >50 lines)
- Missing tests for new logic
- TODO/FIXME comments in production code
🔵 MINOR (Nice to fix):
- Convention violations (naming, formatting)
- Missing documentation
- Unused imports/variables
- Magic numbers without constants
Output Format:
1. Issue Summary Section:
- \"⚠️ [SEVERITY] ISSUES DETECTED\" or \"✓ No critical issues detected\"
- List issues by severity with file:line location
- Include SonarQube-like quality gate status (PASSED/FAILED)
2. Branch Recommendations Section:
Format: category/short-description
Examples: feature/user-auth, fix/memory-leak, refactor/api-cleanup
- If blocker issues: Prefix with \"⚠️ BLOCKED: \"
- If critical issues: Prefix with \"⚠️ REVIEW REQUIRED: \"
3. Commit Messages Section:
Format: type(scope): brief description
- Match each branch recommendation
- Include issue severity prefix if applicable
- Provide 5 conventional commit messages paired with branches'"
How It Works
- Comprehensive Analysis: AI examines your actual changes with focus on modifications
- Multiple Options: Get 5 different messages to choose from
- Conventional Format: Follows industry standards for commits and branches
- Built-in Code Review: SonarQube-style quality and security scanning
- Severity-based Warnings: Blocks or warns about critical issues before commit
Key Features
Smart File Analysis
Prioritizes analyzing modified files over new ones, focusing on what actually changed and why.
Security & Quality Gates
Four severity levels (Blocker, Critical, Major, Minor) with automatic detection of:
- Security vulnerabilities (SQL injection, XSS, CSRF, hardcoded credentials)
- Critical bugs (null pointers, unhandled exceptions, resource leaks)
- Code smells (complexity, duplication, god classes)
- Performance issues (N+1 queries, inefficient algorithms)
Context-Aware Recommendations
AI reads your actual changes and provides commit messages that reflect the true intent and impact.
Usage
# Generate commit messages with issue scanning
aicommit
# Generate branch names + commit messages
aibranch
Example Output
Clean Codebase (No Issues)
✓ No critical issues detected
Quality Gate: PASSED
1. feat(auth): add user login validation
2. fix(api): implement secure authentication flow
3. feat(security): add login form with validation
4. chore(auth): update user authentication system
5. feat(user): implement login functionality
With Issues Detected
⚠️ CRITICAL ISSUES DETECTED
Quality Gate: FAILED
🟠 CRITICAL:
- auth.js:42 - Hardcoded API key in source code
- login.js:15 - Missing input sanitization (XSS risk)
🟡 MAJOR:
- utils.js:87 - High cyclomatic complexity (score: 15)
- api.js:120 - Missing error handling for async operation
1. ⚠️ REVIEW REQUIRED: feat(auth): add user login validation
2. ⚠️ REVIEW REQUIRED: fix(security): implement authentication with input validation
3. ⚠️ REVIEW REQUIRED: feat(api): add login endpoint with security fixes
4. ⚠️ REVIEW REQUIRED: chore(auth): update authentication system and remove hardcoded credentials
5. ⚠️ REVIEW REQUIRED: fix(critical): implement secure login with sanitization
Best Practices
- Run before committing: Catch issues early in development
- Address blocker issues: Never commit code with blocker-level problems
- Review critical warnings: Assess impact before merging
- Use scopes wisely: Indicate project area for better tracking
- Customize for your team: Adjust severity levels and rules as needed