Streamlining Git Commits with AI: Using Ollama Commit Extension for Better Conventional Commits
Use the Ollama commit extension to generate Conventional Commit messages locally with an LLM.
Writing meaningful git commit messages is one of those developer tasks that everyone knows is important, yet many of us struggle with consistently. How many times have you stared at a diff, trying to craft the perfect commit message, only to settle for something generic like "fix stuff" or "update code"?
If this sounds familiar, you're not alone. Fortunately, there's a powerful solution that combines the convenience of local AI with the structure of conventional commits: the Ollama Commit extension for VS Code.
What is Ollama Commit?
Ollama Commit (by DesislavArashev) is a VS Code extension that leverages local AI models through Ollama to automatically generate commit messages based on your staged changes. Instead of wrestling with writer's block every time you commit, you can let AI analyze your diff and suggest appropriate commit messages following conventional commit standards.
The extension integrates seamlessly into your VS Code workflow, allowing you to generate commit messages without leaving your editor or sending your code to external services.
Why Conventional Commits Matter
Before diving into the technical setup, let's briefly touch on why conventional commits are worth adopting:
- Consistency: Every commit follows the same format, making your git history more readable
- Automation-friendly: Tools can automatically generate changelogs, determine version bumps, and trigger CI/CD workflows
- Better collaboration: Team members instantly understand the nature of changes
- Searchability: Finding specific types of changes becomes much easier
The conventional commit format follows this pattern:
<type>(<scope>): <description>For example:
feat(auth): add OAuth2 login supportfix(api): resolve null pointer exceptiondocs: update installation instructions
Setting Up Ollama Commit with Qwen2.5-Coder
To get the best results from the Ollama Commit extension, you'll want to use a code-focused model like qwen2.5-coder:7b, which excels at understanding code changes and generating appropriate commit messages.
Step 1: Install Prerequisites
First, make sure you have Ollama installed and running:
# Install Ollama (macOS/Linux)
curl -fsSL https://ollama.ai/install.sh | sh
# Pull the qwen2.5-coder model
ollama pull qwen2.5-coder:7bStep 2: Install the Extension
In VS Code, search for "Ollama Commit" by DesislavArashev in the Extensions marketplace and install it.
Step 3: Configure the Perfect Prompt
Here's where the magic happens. The default prompt might not give you the conventional commit format you want, so you'll need to customize it. In your VS Code settings, find the Ollama Commit configuration and update the prompt to:
Generate a git commit message using conventional commit format `<type>(<scope>): <description>` for the following code changes. Use present tense, imperative mood. Types: feat (new feature), fix (bug fix), docs (documentation), style (formatting), refactor (code restructuring), test (tests), chore (maintenance), perf (performance), ci (CI config), build (build system), revert (revert commit). Examples: `feat(auth): add OAuth2 login support`, `fix(api): resolve null pointer exception`, `docs: update installation guide`. Code changes: ```diff{diff}``` Commit message:This single-line prompt provides the AI with:
- Clear format requirements
- Comprehensive type definitions
- Concrete examples
- Specific instructions for tone and tense
Using the Extension in Your Workflow
Once configured, using Ollama Commit becomes incredibly straightforward:
- Stage your changes as you normally would in VS Code's Source Control panel
- Select "Ollama Commit: Generate Message from the VS COde command palette (
F1) - Review and refine the generated message if needed
- Commit your changes
The AI will analyze your staged diff and generate a commit message that follows conventional commit standards, taking into account the specific files changed, the nature of the modifications, and the context of your codebase.
Real-World Benefits
After using this setup for several weeks, I've noticed significant improvements in my development workflow:
- Time Savings: No more staring at empty commit message boxes. The AI generates a solid starting point instantly.
- Consistency: Every commit now follows the same conventional format, making my git history much more professional and readable.
- Better Descriptions: The AI often catches nuances in changes that I might have glossed over, leading to more descriptive and accurate commit messages.
- Reduced Mental Load: One less decision to make during the development process means more mental energy for actual coding.
Tips for Best Results
To get the most out of Ollama Commit:
- Make focused commits: The AI works better with smaller, coherent changesets
- Stage selectively: Use
git add -pto stage only related changes together - Review and edit: Treat the generated message as a starting point, not gospel
- Customize the prompt: Adjust the prompt based on your team's specific conventions
Privacy and Performance Considerations
One of the biggest advantages of using Ollama Commit is that everything runs locally. Your code never leaves your machine, addressing privacy concerns that come with cloud-based AI services. The qwen2.5-coder:7b model strikes an excellent balance between performance and resource usage, generating commit messages quickly without overwhelming your system.
Conclusion
The combination of Ollama Commit extension and a well-crafted prompt transforms commit message writing from a chore into an automated, consistent process. By leveraging local AI with conventional commit standards, you can maintain a professional git history while saving time and mental energy for the work that matters most: writing great code.
Give it a try in your next project – your future self (and your teammates) will thank you for the cleaner, more informative git history.
Have you tried using AI for commit message generation? Share your experiences and tips in the comments below!