Embrace Innovation: Empower Git with AI-Powered Automated Commit Messages

After writing code for your bugfix, changes, and feature, one of the most non-standard steps developers faces is writing a commit message, while sometime you might end up writing under or over info, letting a better writer do the things here which they are expert in, yes your AI.

With the introduction of chatGPT, writing commit messages has become significantly easier for developers. The AI-powered tool can generate high-quality commit messages that accurately describe the changes made in the code.

With an Integrated tool named AICommit, we can connect our workspace and let AI figure out the commit message based on the changes we have made in staged files.

Setting up AI commit

The minimum required version of the node would be Nodejs v14.

Install AI commit

You can start by running the following command and installing aicommit globally in your system. passing ` flag in command lets you install it globally so you can use this in all of your projects on the system.

npm install -g aicommits

Get your OpenAI key

You can get your OpenAI API key from https://platform.openai.com/account/api-keys

If you haven’t, create your account first, set up your billing, and then you can proceed.

Setting up your OpenAI key

Once you retrieve your API key, you can continue configuring your aicommit with the following command.

aicommits config set OPENAI_KEY=<your token>

Upgrading your setup

To check the current version

aicommits --version

If it’s not the latest, upgrade by issuing the command

npm update -g aicommits

Usage

Use in CLI mode

You can call and use aicommit directly from your command line interface while using git.

git add <files...>

aicommit

aicommit by default will pass an unknown flag to the git commit, you can pass it in commit flags

As an example, you can stage all changes in tracked file for your commit:

aicommit --all # or simply -a

Generate multiple commit message recommendation

aicommits --generate <i> # or -g <i>

This may use more tokens, and can add/utlise more API calls/cost

More on Usage

You can also use it like normal git while letting aicommit works in the background, you can use this way via Hook.

Install Hook

aicommit hook install

Uninstall hook

aicommit hook uninstall

Usage

Stage your file and commit:

git add <files...>
git commit # Only generates a message when it's not passed in

If you ever want to write your own message instead of generating one, you can simply pass one in: git commit -m "My message"

Aicommit will generate a commit message and you can pass it back to git, it will open an editor where you can review and edit this.

Save and close the commit.

It’s that simple.

This will not only enhance your productivity but also a bit of review, you can master on commit message, and can be one reason to boost your team’s productivity with your neatly written semantic commit message.


Reference: https://github.com/Nutlope/aicommits