commitski
is a personal Python-based CLI tool designed to streamline the Git commit process by using Large Language Models (LLMs) to generate concise and descriptive commit messages. It supports both local (ollama
) and third-party LLMs (e.g., OpenAI, Anthropic) to analyze staged Git changes and suggest commit messages.
-
Automatic Commit Message Generation:
- Generates a descriptive commit message by analyzing
git diff
outputs. - Supports local LLMs via
ollama
and third-party APIs (e.g., OpenAI's GPT, Anthropic's Claude).
- Generates a descriptive commit message by analyzing
-
Local LLM Support:
- Default integration with
ollama
to ensure privacy and GPU-accelerated processing on your machine.
- Default integration with
-
Third-Party LLM Integration:
- Seamless integration with OpenAI and Anthropic APIs using environment variables.
-
Error Handling:
- Handles scenarios like no staged changes, LLM timeouts, and unsupported LLM providers with informative logs.
-
Detailed Feedback:
- Logs each step of the process, including Git staging, LLM interaction, and Git commands.
-
Human-in-the-Loop:
- User can edit the commit message before its pushed.
-
Python 3.7+
-
Git
-
ollama (if using local LLMs)
- Download Ollama
- Ensure
ollama
is properly configured on your system and that thellama3.2-vision
model is available:ollama pull llama3.2-vision
-
Optional: Third-Party LLM Support
- OpenAI API: Set up an API key with access to models like
text-davinci-003
. - Anthropic API: Set up an API key with access to models like
claude-2
.
- OpenAI API: Set up an API key with access to models like
-
Clone the Repository:
git clone https://github.com/<your-github-handle>/commitski.git cd commitski
-
Make the Script Executable:
chmod +x commitski.py
-
Move to a Directory in Your PATH:
mv commitski.py ~/.local/bin/commitski
- Alternatively, create a symlink from your locally cloned
commitski.py
file to your localbin
directory:ln -s ~/path/to/commitski/commitski.py ~/.local/bin/commitski
- Alternatively, create a symlink from your locally cloned
-
Ensure
~/.local/bin
is in Your PATH: Add this line to your~/.bashrc
or~/.zshrc
(if not already present):export PATH="$HOME/.local/bin:$PATH"
-
Reload Your Shell Configuration:
source ~/.bashrc
Or:
source ~/.zshrc
Run the commitski
tool from any Git repository directory:
commitski
- What Happens:
- Stages all changes using
git add .
. - Analyzes the staged changes using your chosen LLM.
- Generates a commit message and commits the changes.
- Pushes the changes to the remote repository.
- Stages all changes using
To specify a third-party LLM provider:
commitski <provider>
- Examples:
- Use OpenAI:
commitski openai
- Use Anthropic:
commitski anthropic
- Use OpenAI:
[2024-12-07 15:00:00] Starting the commit process...
[2024-12-07 15:00:01] Staging all changes...
[2024-12-07 15:00:02] Retrieving git changes...
[2024-12-07 15:00:03] Preparing prompt for Ollama...
[2024-12-07 15:00:04] Sending request to Ollama LLM...
[2024-12-07 15:00:30] Received response from Ollama.
[2024-12-07 15:00:31] Committing changes with message: Update README and FAQ sections.
[2024-12-07 15:00:32] Pushing changes to remote repository...
[2024-12-07 15:00:33] Push completed.
[2024-12-07 15:00:33] Commit process completed successfully.
To use third-party LLMs, set the following environment variables:
-
OpenAI:
export OPENAI_API_KEY=<your_openai_api_key>
-
Anthropic:
export ANTHROPIC_API_KEY=<your_anthropic_api_key>
To persist these, add them to your shell configuration:
echo 'export OPENAI_API_KEY=<your_openai_api_key>' >> ~/.bashrc
echo 'export ANTHROPIC_API_KEY=<your_anthropic_api_key>' >> ~/.bashrc
source ~/.bashrc
By default, commitski
now provides an opportunity to review and modify the generated commit message before finalizing the commit:
-
Edit: Press
E
to open the commit message in your default editor (defined by theEDITOR
environment variable). After you close the editor, the modified message will be used for the commit. -
Accept: Press
A
to accept the generated message as-is and proceed with the commit. -
Cancel: Press
C
to abort the commit process altogether.
This ensures you have full control over the final commit message while still leveraging the power of LLMs to generate a suitable starting point.
The tool will detect this and exit with the message:
Error: No changes to commit.
Ensure you have ollama
installed and a model downloaded then set the OLLAMA_MODEL
variable in commitski.py
.
Third-party LLMs like OpenAI and Anthropic require valid API keys, which you must set as environment variables. The tool uses their APIs to process prompts and return commit messages.
Yes, you can edit the PROMPT
variable in commitsky.py
.
commitski
is provided as-is and intended for personal and non-commercial use only. It is not designed, tested, or recommended for production environments or critical workflows.
By using this tool, you acknowledge and agree that:
- Any outputs (including commit messages) are generated by external Large Language Models (LLMs) and may contain inaccuracies, errors, or unintended content.
- You assume all responsibility and risk for any actions taken based on the output of
commitski
. - The author(s) and contributors shall not be held liable for any damages, losses, or issues arising from the use or misuse of this tool.
Use at your own discretion and always review commit messages before finalizing.
This project is licensed under the MIT License.