How to Automatically Generate Commit Messages for GitHub using aicommits

Sometimes you may feel overwhelmed or uninspired to write commit messages for the changes you make in a codebase, but not anymore, thanks to aicommits!

All of us know the importance of commit message conventions, but writing a meaningful message for every change can be a tedious and time-consuming process, which is why tools like aicommits are becoming increasingly popular.

aicommit is a new tool that uses the OpenAI API to look at your code and automatically make a commit message that is concise and relevant about the changes that you made to the code.

So let’s see how you can install aicommits on your computer to write a meaningful commit message in no time.

Install aicommits

For this, you first need to have NodeJS v14 or later and the npm package manager installed on your machine. If it is already there, then you can skip this step and proceed to Step 2 of this article to install “aicommits” from the npm package manager.

Step 1: Install NodeJS and npm

NodeJS and npm can be easily found in the official repository of Ubuntu or Debian, but the point is that you will find the older version of NodeJS, which will not work with this tool, so to get the required version of NodeJS, execute the following command :

$ curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
$ sudo apt install -y nodejs

Once the installation is done, you can test for the presence of nodejs v14.x and the latest npm version by executing the next line of command into your terminal.

$ node -v && npm --version 

Step 2: Install aicommits

After confirming nodejs and npm, let’s run another command to install the aicommit tool, which will suggest commit messages for your changes to the code automatically when you execute “aicommit”.

$ sudo npm install -g aicommits

Step 3: Get OpenAI API key

For this purpose, you need to go to https://platform.openai.com/account/api-keys to get the API key. If you already have an account with OpenAI, you can use that or create a new one.

Once you have the API key, run the following command, replacing <your_token> with your token key, to save it in the ~/.aicommits file.

$ echo "OPENAI_KEY=<your_token>" >> ~/.aicommits

Note: The OpenAI API is a paid service, but you will receive $18 in free credit, which you can use to test this feature.

Generate an Auto-commit Message for Changes.

Let’s take a look at how you can generate a commit message based on changes to the project directory or any file, and for this, you need to have a project that is initialised with a Git repository.

To show you how it works, let me demonstrate it by making changes to a sample file in the repository by making some changes to the source file “src/commands/aicommits.ts”.

When you invoke the aicommits command, it will check the changes that you made to the respective file, and after the analysis, it will give a commit message.

If the message is as per your expectation, then you choose “Yes” to successfully commit the changes, and if you don’t like it, you can choose “No” to discard the commit message.

And here is the result of the changes.

aicommit suggest commit message
A commit message is suggested by aicommit tool

If you are wondering how it works, let me tell you that it basically uses the git diff command to compare the before and after versions of the file and send them to OpenAI GTP-3 to generate a commit message that best describes your changes.

Wrap up

After using it for a couple of hours, yes, it is interesting to use it when you want AI to write commit messages for you, but there are some limitations, which are already on the developer’s to-do list for the project.

As this project is in development state, so you will find many new features in the upcoming days, like when you don’t prefer to use the suggested message, then you can type your own message, add support for diffs greater than 200 lines, and many more. So stay tuned with aicommit to get the latest updates.

So stay tuned to aicommit to get the latest updates, and be sure to star the project on GitHub.

Before closing this article, I’d like to share 3 free passes and 50% off on registration, which will be on a first-come, first-served basis, for the Southern California Linux Expo (SCaLE 20x).

Keynote speakers this year are:
– Ken Thompson (Creator of Go and Unix)
– Kitty Yeung (Physicist and Artist)
– Arun Gupta (Intel and CNCF)

You check here for the complete list of exhibitors, see https://socallinuxexpo.org/scale/20x/exhibitors

Event Venue: Pasadena, CA
Date: 9 to 12th March

If you are interested in a free pass and discount on registration, contact me at [email protected]

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments