Skip to content

himanshu231204/ai-commit

Repository files navigation

🤖 Ollama Git Commit - AI-Powered Commit Messages

PyPI version PyPI Downloads Python 3.8+ License: MIT GitHub Stars

Generate intelligent git commit messages using your local Ollama instance. No API keys, completely free, and runs offline!


✨ Features

  • 🤖 AI-Powered: Uses local Ollama models to generate commit messages
  • 🔒 Privacy First: Everything runs locally, no data sent to external APIs
  • 🎯 Multiple Styles: Conventional commits, semantic, or detailed formats
  • 💰 Free: No API costs, uses your local Ollama instance
  • Fast: Quick generation with local models
  • 🎨 Interactive: Review, regenerate, or edit messages before committing
  • 🌐 Offline: Works completely offline

📦 Installation

From PyPI (Recommended)

pip install ollama-git-commit

From Source

git clone https://github.com/himanshu231204/ai-commit.git
cd ai-commit
pip install -e .

📋 Prerequisites

Before using Ollama Git Commit, you need:

  1. Python 3.8+

    python --version
  2. Git

    git --version
  3. Ollama - Install Ollama

    # Install Ollama (macOS/Linux)
    curl -fsSL https://ollama.ai/install.sh | sh
    
    # Pull a model (e.g., llama2)
    ollama pull llama2
    
    # Start Ollama server
    ollama serve

💡 Usage

Basic Usage

  1. Stage your changes:

    git add .
  2. Generate commit message:

    ai-commit
  3. Review and choose:

    • y - Accept and commit
    • r - Regenerate message
    • e - Edit message manually
    • n - Cancel

Example Workflow

# Make some changes to your code
echo "print('Hello World')" > hello.py

# Stage the changes
git add hello.py

# Generate AI commit message
ai-commit

# Output:
╔═══════════════════════════════════════════╗
║         🤖 AI Commit Message Tool         ║
║      Powered by Local Ollama 🦙           ║
╚═══════════════════════════════════════════╝

🔍 Checking Ollama server...
✓ Ollama server is running

📊 Changes:
  + 1 lines added
  - 0 lines removed

🤖 Generating commit message...

Generated Commit Message:
──────────────────────────────────────────────────
feat: add hello world script
──────────────────────────────────────────────────

Options:
  y - Accept and commit
  r - Regenerate message
  e - Edit message
  n - Cancel

⚙️ Configuration

Custom Ollama Server

If your Ollama server is running on a different host/port, edit ai_commit.py:

ollama = OllamaClient(base_url="http://192.168.1.100:11434")

Change AI Model

ollama = OllamaClient(model="codellama")  # or "mistral", "llama2", etc.

Commit Message Styles

The tool supports three commit message styles:

  1. Conventional Commits (default):

    feat(auth): add user login functionality
    
  2. Semantic:

    Add user login functionality
    
  3. Detailed:

    Add user authentication system
    
    - Implement JWT-based authentication
    - Add login and logout endpoints
    - Create user session management
    

🤖 Auto Model Selection

AI Commit automatically selects the best available model on your system, prioritizing lighter and faster models for optimal performance.

Priority Order (Fastest to Slowest):

  1. phi - Smallest, fastest (Recommended for quick commits)
  2. mistral - Great balance of speed and quality
  3. qwen - Fast alternative
  4. gemma - Google's lightweight model
  5. codellama - Optimized for code
  6. llama2 - Reliable but slower
  7. llama3 - Most powerful but slowest

How It Works:

When you run ai-commit, the tool will:

  1. Check all installed Ollama models
  2. Automatically select the lightest/fastest available
  3. Display which model was chosen
  4. Generate your commit message

Example Output:

$ ai-commit

╔═══════════════════════════════════════════╗
║         🤖 AI Commit Message Tool         ║
║      Powered by Local Ollama 🦙           ║
╚═══════════════════════════════════════════╝

🔍 Checking Ollama server...
✓ Ollama server is running

Available models (3):
  • phi:latest
  • mistral:latest
  • llama2:latest

✓ Auto-selected: phi:latest
  (Prioritizing lighter/faster models)

📊 Changes:
  + 8 lines added
  - 0 lines removed

🤖 Generating commit message...

Recommended Setup:

For best performance, install a lightweight model:

# Fastest (Recommended)
ollama pull phi

# Good balance
ollama pull mistral

# For code-heavy projects
ollama pull codellama

Manual Model Override:

If you want to use a specific model, you can set an environment variable:

Windows:

set OLLAMA_MODEL=mistral
ai-commit

Linux/Mac:

export OLLAMA_MODEL=mistral
ai-commit


📝 Examples

Example 1: Adding a New Feature

$ git add new_feature.py
$ ai-commit

Generated: feat: add user profile management feature

Example 2: Bug Fix

$ git add bug_fix.py
$ ai-commit

Generated: fix: resolve null pointer exception in login

Example 3: Documentation

$ git add README.md
$ ai-commit

Generated: docs: update installation instructions

🐛 Troubleshooting

Ollama Not Running

Error: Cannot connect to Ollama
Solution: Start Ollama server with `ollama serve`

No Staged Changes

Error: No staged changes found
Solution: Stage your changes with `git add <files>`

Model Not Found

Error: Model not found
Solution: Pull the model with `ollama pull llama2`

🤝 Contributing

Contributions are what make the open-source community amazing! Any contributions you make are greatly appreciated.

How to Contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (when available)
  5. Commit using ai-commit! 😄
  6. Push to your branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.


📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments

  • Ollama - For making local LLMs accessible
  • Git - The best version control system
  • Python - For being awesome
  • You - For using this tool!

🗺️ Roadmap

  • Initial release on PyPI
  • Configuration file support (.ai-commit.yml)
  • More commit message formats
  • Interactive model selection
  • Emoji support in commits 🎉
  • Multiple language support
  • Git hooks integration
  • VSCode extension
  • Custom prompt templates
  • Commit message history
  • Auto-detect commit type from files
  • Batch commit support
  • Integration with GitHub CLI

👨‍💻 Author

Himanshu Kumar


💖 Support

If you find this project helpful, please consider:


📊 Stats

GitHub stars GitHub forks GitHub watchers PyPI downloads


🔗 Links


🌟 Star History

Star History Chart


📣 Show Your Support

Give a ⭐️ if this project helped you!


Made with ❤️ by Himanshu Kumar


🚀 Quick Links

Resource Link
📦 Install pip install ollama-git-commit
📖 Docs GitHub
🐛 Issues Report Bug
💡 Feature Request Request Feature
💬 Discussions Join Discussion
Star Star on GitHub

About

🤖 Generate intelligent git commit messages using local Ollama AI models. Free, private, and works offline!

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors