Skip to content

LemonMantis5571/Git-AutoCommit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Git-AutoCommit πŸ€–

AI-powered git commit message generator using Google's Gemini AI. Automatically create professional, conventional commit messages from your staged changes.

License: MIT Python 3.7+

✨ Features

  • πŸ€– AI-Powered: Uses Google Gemini to analyze your changes and generate meaningful commit messages
  • πŸ“ Conventional Commits: Follows the Conventional Commits standard
  • ⚑ Easy to Use: Simple CLI with multiple modes (auto, interactive, dry-run)
  • 🎯 Smart Analysis: Intelligently summarizes large diffs to focus on key changes
  • πŸ”§ Configurable: Customize behavior with YAML config files
  • πŸš€ Quick Setup: One-command installation with automated scripts

πŸš€ Quick Start

Prerequisites

  • Python 3.7 or higher
  • Git
  • Google Gemini API key

Installation

Option 1: Automated Installation (Recommended)

Cross-Platform (Python):

git clone https://github.com/LemonMantis5571/Git-AutoCommit.git
cd Git-AutoCommit
python install.py

Linux/Mac (Shell Script):

git clone https://github.com/LemonMantis5571/Git-AutoCommit.git
cd Git-AutoCommit
chmod +x install.sh
./install.sh

The installation script will:

  • Check for Python and Git
  • Install the package and dependencies
  • Set up your API key (environment variable)
  • Let you choose a Gemini model (gemini-2.5-flash, gemini-2.5-pro, etc.)
  • Create the git aic alias (optional)
  • Show usage instructions

After installation, use: python -m git_suggest

Option 2: Manual Installation

# Clone the repository
git clone https://github.com/LemonMantis5571/Git-AutoCommit.git
cd Git-AutoCommit

# Install the package
pip install -e .

# Set your API key (choose one method)
# Windows:
setx api_key "YOUR_GEMINI_API_KEY"

# Linux/Mac (add to ~/.bashrc or ~/.zshrc):
export api_key="YOUR_GEMINI_API_KEY"

# Optional: Create git alias
git config --global alias.aic '!python -m git_suggest'

Option 3: Install from GitHub (Coming Soon)

pip install git+https://github.com/LemonMantis5571/Git-AutoCommit.git

πŸ“– Usage

Basic Usage

# Stage your changes
git add .

# Generate and commit with AI message
python -m git_suggest

CLI Options

python -m git_suggest --help              # Show help message
python -m git_suggest --version           # Show version
python -m git_suggest --dry-run           # Preview message without committing
python -m git_suggest --interactive       # Review/edit message before committing
python -m git_suggest --config PATH       # Use custom config file
python -m git_suggest --verbose           # Enable verbose output

Using the Git Alias

If you set up the git aic alias during installation:

git add .
git aic                         # Same as python -m git_suggest

Interactive Mode

Interactive mode lets you review, edit, or regenerate the message before committing:

python -m git_suggest --interactive

You'll see:

============================================================
Generated commit message:
============================================================

  feat: add user authentication endpoint

============================================================

Options: [c]ommit, [e]dit, [r]egenerate, [a]bort:
  • c: Commit with the generated message
  • e: Edit the message manually
  • r: Ask AI to generate a new message
  • a: Abort without committing

Dry Run Mode

Preview the AI-generated message without committing:

python -m git_suggest --dry-run

Output:

feat: add user authentication endpoint

βš™οΈ Configuration

Create a .gitcommit.yml file in your home directory (~/.gitcommit.yml) or project root:

# Google Gemini model to use
model: gemini-2.0-flash-exp

# Maximum diff lines before summarization
max_diff_lines: 300

# Environment variable name for API key
api_key_env: api_key

See .gitcommit.yml.example for more details.

πŸ“ Commit Message Format

Generated messages follow the Conventional Commits specification:

Type Description Example
feat: New features feat: add user login endpoint
fix: Bug fixes fix: resolve null pointer in auth
docs: Documentation docs: update API documentation
style: Code style/formatting style: format code with prettier
refactor: Code refactoring refactor: simplify user service
test: Tests test: add unit tests for auth
chore: Maintenance chore: update dependencies

πŸ”§ Troubleshooting

"api_key environment variable not set"

Solution:

  1. Make sure you've set the environment variable
  2. Windows: Restart your terminal after running setx
  3. Linux/Mac: Run source ~/.bashrc or restart terminal

Verify it's set:

# Windows (PowerShell)
echo $env:api_key

# Linux/Mac
echo $api_key

"Error calling Gemini API"

Possible causes:

  • Invalid API key
  • No internet connection
  • API quota exceeded

Solution: Verify your API key at Google AI Studio

"No staged changes found"

Solution: Stage files before running:

git add <files>
git-suggest

Command not found: git-suggest

Solution: Make sure the package is installed:

pip install -e .

Or use the full Python module path:

python -m git_suggest

🎯 Examples

Example 1: Quick Commit

$ git add src/auth.py
$ python -m git_suggest
[main abc1234] feat: add JWT authentication
 1 file changed, 45 insertions(+)

Example 2: Review Before Committing

$ git add .
$ python -m git_suggest --interactive
============================================================
Generated commit message:
============================================================

  refactor: restructure database models

============================================================

Options: [c]ommit, [e]dit, [r]egenerate, [a]bort: c
[main def5678] refactor: restructure database models
 3 files changed, 120 insertions(+), 45 deletions(-)

Example 3: Preview Only

$ git add README.md
$ python -m git_suggest --dry-run
docs: update installation instructions

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is open source and available under the MIT License.

πŸ™ Acknowledgments

πŸ”— Links


Made by LemonMantis5571

About

Generates Conventional Commits using AI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published