π€ AI-powered Git commit message improver using OpenAI API
git-smartmsg is a command-line tool that analyzes your Git commit history and generates improved commit messages using AI. It operates in two phases: planning (analyzing commits and generating suggestions) and applying (rewriting history with improved messages on a new branch).
ζ₯ζ¬θͺη README γ―γγ‘γ | Japanese README here
- π― AI-Powered: Uses OpenAI API to generate meaningful commit messages
- π Safe by Design: Creates new branches, never modifies your current branch
- π Two-Phase Process: Plan first, review, then apply
- π¨ Emoji Mode: Optional emoji prefixes for visual commit categorization
- β‘ Conventional Commits: Supports conventional commit format
- π‘οΈ History Preservation: Maintains author information and timestamps
- π Flexible Range: Process specific commit ranges or recent commits
- Go 1.25+
- Git
- OpenAI API Key
git clone https://github.com/yourusername/git-smartmsg
cd git-smartmsg
go build -o git-smartmsg main.go# Move to a directory in your PATH
sudo mv git-smartmsg /usr/local/bin/
# Or create a symlink
ln -s $(pwd)/git-smartmsg /usr/local/bin/git-smartmsgexport OPENAI_API_KEY="your-openai-api-key"# Custom API endpoint (for OpenAI-compatible services)
export OPENAI_API_BASE="https://api.openai.com/v1"
# Default model (defaults to gpt-5-nano)
export OPENAI_MODEL="gpt-4o"-
Navigate to your Git repository
cd your-git-repo -
Generate improved commit messages
./git-smartmsg plan --limit 5
-
Review the generated plan
cat plan.json
-
Apply the improved messages to a new branch
./git-smartmsg apply --branch improved-messages
git-smartmsg <subcommand> [options]git-smartmsg plan [options]Options:
--limit <n>: Number of commits from HEAD to include (default: 20)--range <range>: Explicit git range (e.g.,HEAD~10..HEAD)--model <model>: LLM model to use (default: from env orgpt-5-nano)--emoji: Use emoji-style commit messages--allow-merges: Include merge commits (not recommended)--out <file>: Output plan file (default:plan.json)--timeout <duration>: Per-commit AI timeout (default: 25s)
git-smartmsg apply [options]Options:
--branch <name>: New branch name (required)--in <file>: Plan file path (default:plan.json)--allow-merges: Attempt to preserve merge commits (experimental)
git-smartmsg commit [options]Options:
--model <model>: LLM model to use (default: from env orgpt-5-nano)--emoji: Use emoji-style commit messages--timeout <duration>: AI timeout (default: 25s)--auto: Auto-commit without confirmation
# Improve last 10 commits
./git-smartmsg plan --limit 10
# Use specific model
./git-smartmsg plan --limit 5 --model gpt-4o
# Apply to new branch
./git-smartmsg apply --branch feature/improved-commits
# Generate AI commit message from staged changes
git add .
./git-smartmsg commit
# Use emoji mode for commit
git add src/
./git-smartmsg commit --emoji
# Auto-commit without confirmation
git add .
./git-smartmsg commit --auto# Process specific range
./git-smartmsg plan --range v1.0.0..HEAD
# Use emoji mode
./git-smartmsg plan --emoji --limit 15
# Include merge commits (experimental)
./git-smartmsg plan --allow-merges --limit 20
./git-smartmsg apply --allow-merges --branch with-merges# 1. Check what commits you want to improve
git log --oneline -10
# 2. Generate plan with emoji mode
./git-smartmsg plan --emoji --limit 10
# 3. Review the suggestions
cat plan.json | jq '.items[] | {old: .old_message, new: .new_message}'
# 4. Apply to a new branch
./git-smartmsg apply --branch feature/ai-improved-messages
# 5. Review the new branch
git log --oneline -10
# 6. Push when satisfied (optional)
git push --force-with-lease origin feature/ai-improved-messages# 1. Make your changes
echo "console.log('Hello World');" > hello.js
# 2. Stage your changes
git add hello.js
# 3. Generate AI commit message and review
./git-smartmsg commit --emoji
# Interactive prompt example:
# π€ Generating commit message from staged changes...
#
# π Generated commit message:
# π Add hello world example in JavaScript
#
# β Commit with this message? [y/N/e(dit)]: y
# β
Successfully committed with message:
# π Add hello world example in JavaScript
# 4. Push your commit
git push origin mainWhen using --emoji flag, commit messages are prefixed with contextual emojis:
| Emoji | Code | Usage |
|---|---|---|
| π¨ | :art: |
Improving code structure/format |
| π | :bug: |
Fixing bugs |
| π₯ | :fire: |
Removing code or files |
| π | :memo: |
Writing docs |
| β‘ | :zap: |
Improving performance |
| β | :white_check_mark: |
Adding tests |
| π | :lock: |
Security fixes |
| β¬οΈ | :arrow_up: |
Upgrading dependencies |
Example Output:
π¨ Refactor user authentication module
π Fix null pointer exception in data parser
π Update API documentation for v2 endpoints
β
Add unit tests for payment processing
- Clean Worktree Required: Ensures no uncommitted changes (ignores
plan.json) - New Branch Creation: Never modifies your current branch
- Author Preservation: Maintains original author info and timestamps
- Backup Recommendations: Original commits remain accessible
- Review Before Applying: Always check
plan.jsonbefore runningapply - Use Small Batches: Process 10-20 commits at a time for better results
- Test Branch: Review the generated branch before merging
- Team Coordination: Coordinate with team before force-pushing rewritten history
- Backup: Consider creating a backup branch before major rewrites
# Use --force-with-lease for safer force pushing
git push --force-with-lease origin your-branch-name.
βββ main.go # Complete application
βββ go.mod # Go dependencies
βββ go.sum # Dependency checksums
βββ plan.json # Generated plan (ignored by git)
βββ CLAUDE.md # Claude Code guidance
βββ README.md # This file
"worktree is not clean"
- Commit or stash your changes first
plan.jsonis automatically ignored
"AI failed for commit" / "AI failed to generate message"
- Check your OpenAI API key
- Verify API quota/limits
- Try a smaller batch size
"no staged changes found"
- Use
git addto stage your changes before runningcommit - Check
git statusto see what files are available to stage
"cherry-pick failed"
- Complex conflicts may require manual resolution
- Consider excluding merge commits with default settings
# Show available commands
./git-smartmsg
# Show command-specific help
./git-smartmsg plan --help- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI API for AI-powered message generation
- Conventional Commits for commit message standards
- gitmoji for emoji inspiration