Intelligent git commit agents that analyze your changes and generate meaningful conventional commit messages automatically.
- π Smart Analysis: Analyzes git diffs to understand the nature of your changes
- π¬ Conventional Commits: Generates commit messages following the Conventional Commits specification
- π― Context-Aware: Detects file types, function names, and change patterns
- π Multiple Suggestions: Provides several commit message options to choose from
- β Validation: Validates commit messages against conventional commit standards
- π Interactive & Automated: Supports both interactive and automated workflows
- π Cross-Platform: Works on Windows, macOS, and Linux with Node.js
- Node.js 14+ - Download from nodejs.org
- Git - Download from git-scm.com
- OpenAI API Key (optional) - Get from platform.openai.com for GPT features
# Download or clone the smart-commit project
git clone https://github.com/vfa-tanna/smart-commit.git
cd smart-commit
# Run the installation script
node install.js# Clone the repository
git clone https://github.com/vfa-tanna/smart-commit.git
cd smart-commit
# Install dependencies
npm install
# Install globally (optional, for system-wide access)
npm install -g .To use GPT-powered commit message generation:
# Create .env file
cp env.example .env
# Edit .env and add your OpenAI API key
OPENAI_API_KEY=your_openai_api_key_hereGet your API key from OpenAI Platform.
# Download Node.js from https://nodejs.org
# Then run:
node install.js- Install Node.js from nodejs.org
- Install Git from git-scm.com
- Clone or download the project
- Run:
npm install - Run:
npm install -g .(for global installation)
The most user-friendly way to commit:
# Stage your changes first
git add .
# Run the smart commit agent
smart-commitThis will:
- Analyze your staged changes
- Show you a summary of what changed
- Suggest multiple commit messages
- Let you choose or write a custom message
- Validate the message and commit
For quick commits with generated messages:
# Auto-stage all changes and commit with generated message
smart-commit --stage-all --auto
# Use GPT for better message generation
smart-commit --stage-all --auto --gpt
# Or with staged changes
git add .
smart-commit --autoTo just see what the agent detects without committing:
git add .
smart-commit --analyze-onlyTo use a custom message with validation:
git add .
smart-commit --auto --message "feat(auth): add login functionality"smart-commit [OPTIONS]
Options:
-a, --auto Automatically commit with generated message
-m, --message TEXT Custom commit message
-s, --stage-all Stage all changes before committing
--analyze-only Only analyze changes, don't commit
--dry-run Show what would be committed without committing
--gpt Use GPT to generate commit messages (requires OPENAI_API_KEY)
--gpt-model MODEL GPT model to use (default: gpt-4o-mini)
--no-gpt Disable GPT even if API key is available
-h, --help Show help messageThe analyzer examines:
- File types: Python, JavaScript, Go, etc.
- Change patterns: Added, modified, deleted files
- Code entities: Function and class names
- Statistics: Lines added/removed, files changed
Based on the analysis, it generates:
- Type:
feat,fix,docs,refactor, etc. - Scope: Derived from file types or directory structure
- Description: Context-aware description of changes
Generated messages follow the format:
type(scope): description
body (optional)
Examples:
feat(auth): add user login functionalityfix(api): resolve null pointer exception in user servicedocs: update README with installation instructionsrefactor(utils): simplify date formatting helper
# After adding a new authentication module
$ git add auth.py
$ smart-commit
π Analyzing changes...
π Change Analysis:
Type: feature
Scope: python
Files: 1
Lines: +45 -2
Functions/Classes: login, authenticate
π‘ Suggested commit messages:
1. feat(python): add auth
2. feat(python): implement auth
3. feat: update 1 file
Select a commit message (1-5): 1
π Final commit message:
"feat(python): add auth"
Proceed with commit? (Y/n): y
β
Commit successful!$ git add src/utils.py
$ smart-commit --auto
π Committing with message: "fix(utils): resolve validation error"
β
Commit successful!$ git add src/auth.js
$ smart-commit --gpt
π€ GPT mode enabled (model: gpt-4o-mini)
π Analyzing changes...
π Change Analysis:
Type: feature
Scope: javascript
Files: 1
Lines: +67 -12
Functions/Classes: authenticate, validateToken
π‘ Suggested commit messages:
1. feat(auth): implement JWT authentication with token validation
2. feat(auth): add secure user authentication system
3. feat(auth): implement token-based authentication
Select a commit message (1-5): 1
β
Commit successful!Edit config/commit-agents.yaml to customize:
# Commit message rules
message_rules:
max_subject_length: 72
max_body_line_length: 100
use_imperative_mood: true
# File type mappings
file_types:
source_code:
- .py
- .js
- .go
# ... more mappingsAdd to your .gitconfig:
[alias]
sc = !smart-commit
sca = !smart-commit --stage-all --autoUsage:
git sc # Interactive commit
git sca # Auto-stage and commitCreate .git/hooks/prepare-commit-msg:
#!/bin/sh
# Generate commit message if none provided
if [ -z "$2" ]; then
smart-commit --analyze-only --dry-run > /tmp/commit-suggestion
echo "# Suggested by smart-commit:" >> "$1"
cat /tmp/commit-suggestion >> "$1"
fi- Languages: Python, JavaScript, TypeScript, Go, Java, C++, Rust, Ruby, PHP
- Web: HTML, CSS, SCSS, Vue, Svelte
- Config: JSON, YAML, TOML, XML
- Documentation: Markdown, RST, TXT
- Scripts: Bash, Zsh, PowerShell
Following Conventional Commits:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Formatting, missing semicolons, etc.refactor: Code change that neither fixes a bug nor adds a featureperf: Performance improvementstest: Adding or updating testsbuild: Build system or external dependenciesci: CI configuration changeschore: Other changes (maintenance, etc.)revert: Reverts a previous commit
β No staged changes to commit
π‘ Use 'git add <files>' to stage changes or use --stage-all flagSolution: Stage your changes with git add or use --stage-all
β Not in a git repositorySolution: Run the command inside a git repository
Error: Cannot find module 'yaml'Solution: Install dependencies with npm install
GPT failed: OpenAI API key not providedSolutions:
- Create a
.envfile in the project root - Add
OPENAI_API_KEY=your_api_key_here - Get your API key from platform.openai.com
Invalid OpenAI API keySolutions:
- Check your API key is correct
- Ensure you have credits in your OpenAI account
- Verify the API key has the necessary permissions
# Run the test script to verify everything is working
node test-installation.js'node' is not recognized as an internal or external commandSolutions:
- Install Node.js from nodejs.org
- Restart your command prompt after installation
- Check if Node.js is added to PATH
'npm' is not recognized as an internal or external commandSolutions:
- Reinstall Node.js (npm comes with Node.js)
- Check if npm is in your PATH
- Try using
npxinstead
Error: EACCES: permission deniedSolutions:
- Run Command Prompt as Administrator
- Use
npm install -g . --unsafe-perm - Or install locally and use
npx smart-commit
Error: EACCES: permission deniedSolutions:
- Use
sudo npm install -g . - Or configure npm to use a different directory:
npm config set prefix ~/.npm-global - Add
~/.npm-global/binto your PATH
Extend the DiffAnalyzer class to add custom change detection patterns:
const DiffAnalyzer = require('./lib/diff-analyzer');
class CustomAnalyzer extends DiffAnalyzer {
constructor() {
super();
// Add custom patterns
this.changePatterns['migration'] = [
/add.*migration/i, /create.*table/i, /alter.*column/i
];
}
}Extend the MessageGenerator class:
const MessageGenerator = require('./lib/message-generator');
class CustomGenerator extends MessageGenerator {
generateSubject(analysis) {
// Custom logic here
return super.generateSubject(analysis);
}
}- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Update documentation
- Submit a pull request
MIT License - see LICENSE file for details.
- Major rewrite: Converted from Python to Node.js for better cross-platform support
- GPT Integration: Added OpenAI GPT support for intelligent commit message generation
- Enhanced CLI: Improved command-line interface with better error handling
- Environment Configuration: Added .env file support for API keys
- Better UX: Enhanced interactive mode with colored output and better prompts
- Interactive and automatic commit modes
- Support for major programming languages
- Conventional commit message generation
- Configurable rules and patterns