A CLI tool that generates AI-powered git commit messages.
I was tired of always typing commits so why not build a tool that makes it so I dont have to. Also AI is cool right now. Please let me know your feedback! As I continue to learn Python I thought this would be a cool project to put my skills to the test and collaborate with others!
- AI-Powered Commit Messages: Generates commit messages using OpenAI's GPT models based on the diff of your staged changes.
- Secure API Key Storage: Stores your OpenAI API key securely using your operating system's keyring.
- Flexible Configuration: Supports custom commit messages and optional key updates.
- Language Support: Works with multiple programming languages by analyzing code file types.
The tool processes changes in code files by analyzing the git diff
output, focusing specifically on code additions and deletions. It then uses AI to generate commit messages based on these changes. Non-code-related changes, such as package updates, are ignored to prevent overwhelming the AI API and ensure the focus remains on meaningful code changes.
- Python 3.6 or higher
pip
(Python package installer)- Git installed and configured
pip install ai-commit-tool
Link to PyPi: https://pypi.org/project/ai-commit-tool/
This tool requires an OpenAI API key to function.
Get that key here:
https://platform.openai.com/account/api-keys
This only works on projects that you have initalized with git
Run the tool:
ai-commit
Enter your OpenAI API key here:
Enter your OpenAI API key: your-api-key-here
Save the API key securely:
- The tool will ask if you want to save the API key securely for future use.
- Your API key will be stored in your operating system's keyring.
- Security: The API key remains on your local machine and is never transmitted or shared.
Alternative Method Environment Variable:
Windows:
- Search for "Environment Variables" in the Start menu.
- Click "Edit the system environment variables."
- Click "Environment Variables."
- Under "User variables," click "New."
- Enter OPENAI_API_KEY as the variable name and your API key as the value.
- Click "OK" to save.
if you need to update API key:
ai-commit --update-key
Follow prompts to enter and save new key.
Stage your changes in git:
git add .
Run the AI Commit Tool:
ai-commit
Follow the prompts:
- It will show you a list of changes
- Then generates an commit message based on changes
- You choose to confirm, decline, or edit the commit message
Example output:
---- GENERATED COMMIT MESSAGE ----
"Refactor: Improved performance of data processing module."
Do you want to commit using this message? (y/n/c):
y
commits the messagen
cancels the commitc
custom commit message
Contributions are welcome! Heres how:
-
Fork the repository on GitHub.
-
Clone your fork locally:
git clone https://github.com/awkwardlysocial/ai-commit-tool.git
- Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name
- Make your changes and commit them:
ai-commit
or
git commit -m "Description of your changes"
- Push to your fork:
git push origin feature/your-feature-name
- Submit a pull request to the main repository.
- Follow the existing coding style.
- Include comments where appropriate.
- Update the README.md if your changes affect usage or setup.
- Ensure that your code passes any existing tests.
This project is licensed under the terms of the MIT License.