Using OpenCommit to Automate and Improve Git Commit Messages
Hey there, fellow coder! Let's chat about one of the lesser-loved parts of the coding process - writing those pesky git commit messages. You're neck-deep in your latest code masterpiece, the creative juices are flowing, but then you have to pause, switch gears, and write a commit message that makes sense. Talk about a mood killer, right?
But what if I told you there's a handy little tool that can do the hard work for you? Meet OpenCommit - your new secret weapon against boring commit messages!
Before you get to enjoy the perks of OpenCommit, you've got to get it set up. But don't worry - it's a walk in the park.
First things first, install OpenCommit globally with npm by whipping out this command:
npm install -g opencommit
After you've got OpenCommit installed, you'll need to connect it with your OpenAI account. Simply grab your API key from OpenAI and feed it to OpenCommit:
opencommit config set OPENAI_API_KEY=<your_api_key>
Just remember, your API key is stashed away locally in a
~/.opencommit config file.
Now for the fun part - using OpenCommit. Whenever I'm in the zone and need to make a commit, I stage my changes using
git add <files...>
git add .
Then, I let OpenCommit take the wheel:
Or if you're more of a shortcut kind of person, you can use the oc command:
Seriously, it's as easy as pie!
And because one size doesn't always fit all, you can tweak OpenCommit to fit your unique style.
By default, OpenCommit uses the GPT-3.5-turbo model (or ChatGPT for the cool kids). But if you're feeling adventurous, you can give the more powerful GPT-4 model a spin:
oc config set model=gpt-4
Who doesn't love a good emoji, right? With OpenCommit, you can sprinkle some fun into your commit messages by adding emojis:
oc config set emoji=true
Want to make your commit messages crystal clear? Add descriptions of your changes:
oc config set description=true
OpenCommit also caters to different languages. You can pick the language for your commit messages. Let's say you want to set it to German:
oc config set language=de
So, there you have it - with OpenCommit, you'll never have to put your coding flow on pause to brainstorm a commit message. More time for the fun stuff, less time for the boring stuff. Just remember, you'll be footing the bill for your own requests to the OpenAI API. OpenCommit uses the ChatGPT (3.5-turbo) model, which is a cool ~15x cheaper than GPT-4. So why not give OpenCommit a whirl? Your commit messages will never be the same!