The gcm script provides a guided flow to create commit with generated messages.
Configuration
First off, we define the script function, which sets up our GenAI script by providing a title and a description, and specifying the model we’ll be using:
Look for changes
Next up, we check for any staged changes in your Git repository using git diff --cached. If there’s nothing staged, GenAI kindly offers to stage all changes for you:
We then log the diff to the console so you can review what changes are about to be committed:
Generate and refine commit message
Here comes the interesting part. We enter a loop where GenAI will generate a commit message for you based on the diff. If you’re not satisfied with the message, you can choose to edit it, accept it, or regenerate it:
Commit and push
If you choose to commit, GenAI runs the git commit command with your message, and if you’re feeling super confident, it can even push the changes to your repository right after:
Running the Script with GenAIScript CLI
Getting this script up and running is a cinch. If you’ve already installed the GenAIScript CLI, you can simply run it with:
Remember, you’ll need to have your changes staged in Git for the script to work its magic. 🧙