Have you ever struggled to write a good Git commit message? I know I have! That’s why I created gc—a CLI tool powered by AI to help you write clear, meaningful commit messages without any hassle.
Why did I build gc?
The idea for gc came from a common developer struggle: writing good commit messages. During one of my collaborative projects, I noticed how unclear and inconsistent commit messages caused confusion. Some were too vague, like “fix stuff,” while others were unnecessarily long. This made it hard to understand the changes when revisiting the code or working with the team.
I wanted to solve this problem by making commit messages simpler and smarter. With AI becoming more accessible, I realized it could help automate this task. The goal was to create a tool that saves time, ensures meaningful commit messages, and lets developers focus on coding instead of worrying about what to write in their Git commits.
gc is my solution: an AI-powered CLI tool that generates clear and context-aware commit messages, but still gives you the flexibility to customize them. It’s all about making Git workflows smoother and reducing stress for developers.
Usage
gc is a globally installable Node.js package designed to make your Git workflow smoother. It’s easy to set up and works seamlessly with any Git repository.
Installation
To install gc, make sure you have Node.js (v16 or higher) and Git installed. Then, run:
npm install -g @utsavdotdev/gc
That’s it! The tool is now ready to use.
Commands
Generate Commit Messages
gc new
Get AI-generated commit message suggestions and select or edit the one you like.
Write Custom Commit Messages
gc new -c
Manually input your own commit message.
Privacy Settings
gc opt-in gc opt-out
Choose whether to share anonymous data to help improve the tool.
Help
gc --help
View a detailed list of commands and how to use them.
Usage
Using gc is as simple as these three steps:
Stage Your Changes
Before running gc, add your changes to the staging area using:git add .
Generate or Write a Commit Message
To let AI suggest commit messages, use:
gc new
To write a custom commit message, use:
gc new -c
Commit or Copy the Message
Once you have your message ready, you can:Copy it to your clipboard for later use.
Open and edit it in your preferred CLI editor to make additional adjustments.
Commit it directly to your repository.
Development Process
Creating gc was an exciting journey that involved several steps to ensure it was useful, reliable, and user-friendly. Here’s a breakdown of the development process:
Stage 1 - Research
To kick off the project, I started by looking into existing solutions like ai-commit and aicommits. Both are CLI tools designed to generate AI-powered commit messages. While they are useful, I noticed a few areas where they could be improved:
Customization: These tools lacked flexibility for users to edit messages easily during the workflow.
Interactive Features: I wanted a more interactive and user-friendly experience for selecting, editing, or copying messages.
Privacy Options: I felt it was important to give users clear control over anonymous data sharing(experimental)
This research gave me a solid foundation and clear direction for building gc, focusing on making it smarter, more flexible, and better suited to developers’ needs.
Stage 2 - Gathering Tech Stack
Since the hackathon was organized by Modus, using their platform for building functions and APIs was a mandatory requirement. Modus integrated Models provided the foundation for generating context-aware commit messages, and integrating it became a key part of the project.
For other aspects of the project, I carefully selected tools to ensure efficiency and scalability:
Next.js: To build a sleek and responsive website for showcasing gc.
Node.js: The backbone of the CLI tool for its performance and simplicity.
Inquirer.js: To create interactive prompts for a seamless user experience.
Commander.js: For command-line argument parsing and structuring the CLI commands.
Clipboardy: To enable copying generated commit messages directly to the clipboard.
Simple-Git: To interact with Git repositories programmatically.
Stage 3 - Building Client Side
The first step in building the client-side was creating the CLI tool, as it’s the core feature of gc. I focused on ensuring the tool was simple to use and provided a seamless experience for developers. Key features like AI-powered commit suggestions, custom messages, and clipboard integration were implemented during this phase.
After finalizing the CLI tool, I moved on to designing the landing page using Next.js and TailwindCSS. The landing page includes a mock terminal box, where users can interact with predefined commands such as:
gc info
: Displays information about the tool.gc features
: Lists the key features of gc.gc commands
: Shows a quick reference for all available CLI commands.cls
orclear
: Clears the terminal screen.
Stage 4 - Integrating Modus
Integrating Modus was a crucial step in the development of gc. This was my first experience with Hypermode and Modus, so I started from scratch. I began by watching the collaborative YouTube video between Hypermode and Hashnode, which helped me understand the basics. Then, I dive into the documentation, exploring code snippets provided by Hypermode. Initially, it was overwhelming, and I felt completely lost. To clear my mind, I decided to focus on completing the client-side part of the project first.
Once I felt refreshed, I returned to setting up Modus, following the documentation step by step. I was able to successfully set it up and generate a simple GraphQL API for a "hello message" function. Thankfully, GraphQL wasn’t new to me, as I had worked with it previously while experimenting with the Hashnode API.
Next, I explored the models I would need. I initially tried using an external model by adding it to the modus.json
file, but I encountered limitations due to free credits running out after testing. Fortunately, I discovered that Hypermode also hosts some models, which worked much better for my needs and provided valid responses.
meta-llama/Meta-Llama-3.1-8B-Instruct
, to power the AI-driven commit message generation feature.After that, I wrote a function that takes a prompt and the Git diff output, then returns an array of commit messages. To fine-tune this function, I tested it approximately 100-130 times, iterating on the prompt to get the most accurate results. However, I ran into a challenge when the service suddenly crashed, showing a 503 error. Fortunately, the Modus team resolved the issue within a couple of hours.
Once everything was up and running, I fine-tuned the responses from the model and displayed them to the user in a clear and meaningful way. This integration of Modus into gc was a key step in making the AI-powered commit message feature come to life.
Stage 5 - Deployment
When it came to deploying Modus, I initially thought it would be a difficult process. However, once I aligned everything in the right way, it turned out to be much easier than I expected.
For the landing page, I hosted it on Vercel, which was quick and simple, allowing it to be live right away.
The CLI tool was published on the npm package registry, making it easy for others to install and use.
As for the Modus functions and APIs, I had to link my GitHub repo to Hypermode using the command:
hyp link
Once linked, it automatically updated the Modus app's endpoints with each commit and provided a production-ready API accessible with the Hypermode API key. This process was surprisingly easy and worked smoothly once everything was set up properly.
Problem Encounter
During the development of gc, I faced a few challenges that required some problem-solving and adjustments:
Modus API Crashes: While testing the integration with Modus, I encountered an issue where the API returned a 503 error. It turned out that this was caused by an overload in requests. Fortunately, the Modus team fixed the issue within a couple of hours, allowing me to continue working without major delays.
External Model Limitations: I initially tried to use an external AI model for generating commit messages by adding it to the
modus.json
file. However, after running out of free credits, I had to find an alternative. Luckily, Hypermode hosted models that worked well, and I was able to use those instead.Fine-Tuning AI Responses: Getting the AI model to generate relevant commit messages based on Git diffs was challenging. I had to test the prompt multiple times—about 100-130 attempts—to refine it and ensure that the responses were meaningful. Even after that, I had to fine-tune the model’s outputs to match the expected results.
Links
🖥️ GitHub Repository: utsavdotdev/gc
🌐 Website: gc
Conclusion
Building gc was a great experience, and I’m happy with how it turned out. It’s a tool that helps developers generate meaningful commit messages using AI, making workflows smoother and more efficient.
A huge thank you to Hashnode and Hypermode for organizing this hackathon and providing the tools and support that made this project possible. 🚀