AI Commits: Intelligent Git Commit Message Generator
Introduction
AI Commits is a command-line interface (CLI) tool that automates the generation of Git commit messages using artificial intelligence. This innovative tool leverages OpenAI's language models to craft meaningful, context-aware commit messages, freeing developers from the routine task of writing commit messages themselves.
Setup
To start using AI Commits, users need to ensure they have the latest version of Node.js v14 or later. Installation is straightforward:
npm install -g aicommits
Next, an API key from OpenAI is required. After creating an account and setting up billing at OpenAI, you can set the API key as follows:
aicommits config set OPENAI_KEY=<your token>
This will create a configuration file named .aicommits
in the user's home directory.
Upgrading
To ensure you're using the latest version of AI Commits, verify the installed version with:
aicommits --version
Update it if necessary with:
npm update -g aicommits
Usage
AI Commits can be used directly in CLI mode. After staging changes in Git, simply run:
aicommits
AI Commits will then generate a suitable commit message. For those who prefer shorter commands, the alias aic
is available.
Generate Multiple Recommendations
When indecisive, users can generate multiple commit message recommendations using:
aicommits --generate <i> # Replace <i> with the number of messages
Conventional Commits
For those following the Conventional Commits specification, AI Commits allows for this format via:
aicommits --type conventional
Git Hook
AI Commits can be integrated directly into Git workflows using the prepare-commit-msg
hook, allowing customized review and editing of AI-generated commit messages.
Install the hook with:
aicommits hook install
Uninstall it with:
aicommits hook uninstall
Configuration
AI Commits offers versatile configuration options. Users can set and retrieve various settings:
- OPENAI_KEY: Essential for using the AI capabilities.
- locale: Sets language preferences for messages.
- generate: Defines the number of alternative messages.
- proxy: Configures an optional proxy for network requests.
- model: Chooses the AI model to use, such as
gpt-3.5-turbo
. - timeout and max-length: Determines the network request time and the character limit for messages.
- type: Optionally, enforce conventional commit formatting.
How it Works
AI Commits functions by analyzing code changes via git diff
, and then sending these changes to OpenAI's API to generate a proposed commit message. It utilizes advanced AI capabilities to understand context and provide concise, accurate suggestions.
Maintainers and Contributions
AI Commits is maintained by Hassan El Mghari (@Nutlope) and Hiroki Osame (@privatenumber). Contributions are welcome, and developers can assist by tackling issues or adding features outlined on the project’s GitHub page. The Contribution Guide provides guidance on how to engage with the project.
AI Commits offers a blend of modern AI capabilities and practical utility, streamlining the often tedious task of crafting commit messages and enhancing productivity for developers around the globe.