cmt is a command-line utility that generates Conventional Commit messages using OpenAI's GPT models based on staged Git changes.
It automates the process of writing clear and structured commit messages, enhancing your Git workflow and ensuring consistency across projects.
- Automated Commit Messages: Generates commit messages following the Conventional Commits specification.
- Interactive Approval: Allows you to review and approve the generated commit message before committing.
- Interactive Edit: Supports editing the commit message interactively before committing.
- Custom Prefixes: Supports adding custom prefixes to commit messages for better traceability (e.g., task IDs, issue numbers).
- Changelog Generation: Automatically creates changelogs based on your commit history.
- Integration with OpenAI GPT: Utilizes GPT to analyze your staged changes and produce meaningful commit messages.
Before installing and using cmt, ensure you have the following:
- Go: Version 1.16 or higher is recommended.
- Git: Ensure Git is installed and initialized in your project.
- OpenAI API Key: Obtain an API key from OpenAI to use GPT models.
-
Clone the Repository
git clone https://github.com/tab/cmt.git
-
Navigate to the Project Directory
cd cmt
-
Set Up Environment Variables
export OPENAI_API_KEY=your-api-key-here
For permanent setup, add the above line to your shell profile (~/.bashrc
, ~/.zshrc
, etc.).
-
Build the Binary
go build -o cmd/cmt cmd/main.go
-
Make the Binary Executable
chmod +x cmd/cmt
-
Move the Binary to Your PATH
sudo ln -s $(pwd)/cmd/cmt /usr/local/bin/cmt
-
Verify Installation
cmt --version
Navigate to your git repository and stage the changes you want to commit:
git add .
Run the cmt
command to generate a commit message:
cmt
Review the generated commit message and choose whether to commit or not.
💬 Message: feat(core): Add user authentication
Implemented JWT-based authentication for API endpoints. Users can now log in and receive a token for subsequent requests.
Accept, edit, or cancel? (y/e/n):
Type y to accept and commit the changes, e to edit message or n to abort.
🚀 Changes committed:
[feature/jwt 29ca12d] feat(core): Add user authentication
2 files changed, 106 insertions(+), 68 deletions(-)
...
Optional prefix for the commit message can be set with the --prefix
flag:
cmt --prefix "TASK-1234"
Resulting commit message:
💬 Message: TASK-1234 feat(core): Add user authentication
Implemented JWT-based authentication for API endpoints. Users can now log in and receive a token for subsequent requests.
Accept, edit, or cancel? (y/e/n):
Run the cmt changelog
to generate a changelog based on your commit history:
cmt changelog SHA1..SHA2
cmt changelog v1.0.0..v1.1.0
The command will output the changelog in the following format:
# CHANGELOG
## [1.1.0]
### Features
- **feat(jwt):** Add user authentication
- **feat(api):** Implement rate limiting for API endpoints
### Bug Fixes
- **fix(auth):** Resolve token expiration issue
...
Q: How do I obtain an OpenAI API key?
A: You can obtain an API key by signing up at OpenAI's website. After signing in, navigate to the API keys section to generate a new key.
Q: How can I ensure that private information isn't shared with OpenAI?
A: Here are some best practices to prevent sharing private information with OpenAI:
-
Review Staged Changes: Before running the
cmt
command, carefully review the changes you have staged usinggit diff --staged
. Ensure that no sensitive information (like passwords, API keys, or personal data) is included. -
Exclude Sensitive Files: Use
.gitignore
to exclude files that contain sensitive information from being tracked and staged. For example:.env secrets/
Distributed under the MIT License. See LICENSE
for more information.
- OpenAI for providing the GPT models.
- Conventional Commits for the commit message specification.