README
ΒΆ
πΎ commit-ai: write your commit messages with AI π€
As a Go developer, I looked at the world and thought:
You know what this planet really needs? One more commit message generator!
So, naturally, I built one. Wellcome to another commit-ai, the tool for generating commit messages using the OpenAI API. It analyzes Git changes and generates concise, meaningful commit messages for your repository.
β¨ Features
- Generates a commit message based on changes staged using
git add. - Automatically extracts changed directories as go packages and adds them to the message (optional).
- Applies rules for creating commit messages: starts with an imperative verb in the present tense, no period at the end, and limited to 10 words.
- Option to exclude package names or the full commit command from the message.
π Requirements
- Go 1.18 or higher
- OpenAI API key (set in the
OPENAI_API_KEYenvironment variable)
π Getting Started
You can install commit-ai directly using Go:
go install github.com/adobromilskiy/commit-ai@latest
Or manually:
-
Clone the repository:
git clone https://github.com/adobromilskiy/commit-ai.git cd commit-ai -
Install dependencies:
go install -
Set your OpenAI API key:
export OPENAI_API_KEY=your-api-key-here
π Usage
Main Command
Run the command:
commit-ai
This will generate a commit message based on the staged changes in your repository.
Flags
--no-pkgβ exclude package names from the commit message.--no-cmdβ output only the commit message without thegit commitcommand.
Command Examples:
- Generate a commit message with package names:
commit-ai
- Generate a commit message without package names:
commit-ai --no-pkg
- Output only the commit message, without the
git commitcommand:
commit-ai --no-cmd
- Generate just the commit message without packages and command:
commit-ai --no-pkg --no-cmd
Example Output
If there are staged changes, the tool may generate a commit message like:
git commit -m "core, database: refactor incoming params"
If the --no-pkg flag is enabled, it will generate:
git commit -m "refactor incoming params"
π οΈ Tricks & Shortcuts
To make working with commit-ai even faster, you can add the following Git aliases:
git config --global alias.addcommit '!f() { git add "$@" && git commit -m "$(commit-ai --no-cmd)"; }; f'
git config --global alias.prepcommit '!git add $@ && commit-ai'
πΉ git addcommit <files>
This alias adds files to staging and immediately commits them using commit-ai to generate the commit message.
Example usage:
git addcommit file1.go file2.go
Equivalent to:
git add file1.go file2.go && git commit -m "$(commit-ai)"
It automatically stages the provided files and runs commit-ai, committing the changes with an AI-generated message.
πΉ git prepcommit <files>
This alias stages files and suggests a commit message without actually committing.
Example usage:
git prepcommit file1.go
Equivalent to:
git add file1.go && commit-ai
This lets you preview the AI-generated commit message before manually committing.
Documentation
ΒΆ
There is no documentation for this package.