AI-powered git commit message generator using OpenAI API.
- Automatically generates clear and descriptive commit messages
- Follows conventional commit format
- Supports multiple OpenAI models
- Flexible configuration options
- Command-line interface with various options
- Detailed logging system
- Auto-commit support
- Auto-push support
- Branch context awareness
pip install git+https://github.com/zo0043/py-ai-commit.git
Basic usage in any git repository:
ai-commit
Command line options:
ai-commit [-h] [-y] [-c CONFIG] [-m MODEL] [--dry-run] [-v]
options:
-h, --help Show this help message
-y, --yes Skip confirmation and commit directly
-c CONFIG, --config CONFIG
Path to specific config file
-m MODEL, --model MODEL
Override AI model from config
--dry-run Generate message without committing
-v, --verbose Show verbose output
You can configure the tool using either a .aicommit
file or a .env
file in your project root or any parent directory.
- Create a
.aicommit
or.env
file:- Copy
.aicommit_template
to.aicommit
- Edit the file with your settings
- Copy
OPENAI_API_KEY=your_api_key # Required: Your OpenAI API key
OPENAI_BASE_URL=your_api_base_url # Required: OpenAI API base URL
OPENAI_MODEL=your_model_name # Required: OpenAI model to use (e.g., gpt-3.5-turbo)
LOG_PATH=.commitLogs # Optional: Directory for log files (default: .commitLogs)
AUTO_COMMIT=true # Optional: Skip confirmation (default: false)
AUTO_PUSH=true # Optional: Auto push after commit (default: false)
The tool will search for configuration files in the following order:
- Command-line specified config file (
-c
option) .aicommit
in current or parent directories.env
in current or parent directories
- Command-line arguments (highest priority)
- Configuration file settings
- Default values (lowest priority)
Enable auto-commit in one of three ways:
- Use
-y
or--yes
flag:ai-commit -y
- Set
AUTO_COMMIT=true
in config file - Interactive confirmation (default)
When enabled with AUTO_PUSH=true
, the tool will:
- Automatically push changes to remote after successful commit
- Use current branch name for pushing
- Only push if commit is successful
- Log push operations and any errors
Use --dry-run
to generate a commit message without actually committing:
ai-commit --dry-run
Override the model from command line:
ai-commit -m gpt-4
Enable detailed logging:
ai-commit -v
The tool automatically includes the current branch name in the commit message generation context for more relevant messages.
Logs are stored in the configured LOG_PATH
directory (default: .commitLogs
):
- Daily log files:
commit_YYYYMMDD.log
- Includes detailed information about:
- Program startup
- Configuration loading
- Git operations
- API calls
- Commit process
- Push operations
- Errors and warnings
The tool includes robust error handling for:
- Missing configuration
- Invalid API keys
- Network issues (with automatic retries)
- Git repository errors
- Invalid staged changes
- Push failures
MIT