AI-Generated GIT Commit Messages - Why and How: Cloud Options

Confidence is a technology enthusiast with an unyielding passion for knowledge acquisition and dissemination. When he's neither hacking tech stacks nor exploring the latest dev frameworks, he enjoys sharing educative pieces and playing the piano.
Version control is probably the most crucial aspect of web and software development today, and a project's commit history is its story, written one change at a time.
Precise commits facilitate effective collaboration. They also help developers reference a specific state in a project's timeline. Many developers who understand the short and long-term significance of crafting clear, consistent commit messages occasionally consider that phase of the job a tedious disruption in their workflow, but does it have to be?
This article introduces easy-to-use AI-powered options that lessen the developer burden of manually drafting adequate commit messages. We'll show you how to adopt each one and highlight probable limitations.
Prerequisites
Introductory knowledge of Git.
An Integrated Development Environment (VSCode preferred).
An existing Git-tracked project/repo.
Auto-Generate Commits with Copilot
GitHub Copilot is Microsoft's flagship AI programming assistant. It seamlessly integrates with VSCode and is capable of analyzing diffs (short for differences) in code versions to suggest appropriate commit messages. It does this by comparing the content of staged files with the content of the most recent commit in a project's git repository.
We'll be using VS Code to demo this, but Copilot can be deployed and utilized on several other IDEs.
Generate Commit Messages with Copilot UI
To set up Copilot as a commit message-generating tool in your workspace, first, install GitHub Copilot and GitHub Copilot chat extension from the VSCode extension marketplace.

Once both extensions are successfully installed, press Control + Command + i (Mac) / Ctrl + Alt + i (Windows/Linux) to open the Copilot chat window and click Sign in to GitHub[dot]com.

Sign in with your GitHub credentials in the pop-up window, then open the VSCode source control menu, or press Ctrl+Shift+G.
Stage file changes in your local git branch.
Click the sparkle icon to generate a commit message.

You can then review the generated message, make adequate modifications, commit changes, and push commits to your cloud git host (e.g., GitHub).
Generate Commit Messages via GitHub Copilot CLI
If you prefer using the terminal instead of the source control user interface, do the following:
First, install GitHub CLI with popular installation packages like Chocolatey (Windows) or Homebrew (macOS).
For Windows
$ choco install ghFor macOS
$ brew install ghAuthenticate GitHub CLI.
$ gh auth loginGo through the instructions and select the appropriate options. Crucially, copy the one-time code and enter it in your browser.
? Where do you use GitHub? GitHub.com ? What is your preferred protocol for Git operations on this host? HTTPS ? Authenticate Git with your GitHub credentials? Yes ? How would you like to authenticate GitHub CLI? Login with a web browser ! First copy your one-time code: XXXX-XXXX Press Enter to open https://github.com/login/device in your browser... ✓ Authentication complete. - gh config set -h github.com git_protocol https ✓ Configured git protocol ✓ Logged in as <your_username>After authentication completion, proceed to install (or update) the Github Copilot CLI extension.
$ gh extension install github/gh-copilot $ gh extension upgrade gh-copilotYou should now be able to use the sparkle icon in the terminal like this:

If you find the above Copilot setup procedure inaccurate due to IDE differences, you might have to consult this guide for specific details regarding its integration in your IDE.

Limitations
As with any free-tier product, there are certain limitations to what the free version of Copilot offers.
Microsoft imposes that Copilot allows only 50 messages and 2000 auto code completions per month. This consequently implies some degree of constraint on the number of commit message generations you can do within 30 days.
Recommendations
Microsoft Copilot is an excellent AI assistant choice. We recommend that you/your organization try Copilot before other alternatives, which we'll cover shortly.
However, if your revenue outlook is solid, we strongly recommend you upgrade to the Copilot Pro tier for $10 per month or $100 annually.
GIT AI Commit by The-Cafe
git-ai-commit is a third-party AI commit message-generating tool built with Python by the-cafe. Compared to Copilot which provides default LLM access to Claude 3.5 Sonnet and OpenAI’s GPT-4o models, it supports a variety of models provisioned by OpenAI, Anthropic, and locally hosted Ollama. (Full list here)
Setting up git-ai-commit
To set up and use git-ai-commit in your project, first, be sure you have Python installed on your development workstation.
Once that's done, follow the instructions below.
Download and install the package.
$ pip install git-ai-commitInstall and upgrade set up tools
$ pip install --upgrade setuptoolsVerify
git-ai-commitpackage installation.$ git-ai-commit --versionYou'll have to add the package folder to your system environment variable path manually if this returns an error, otherwise proceed on Step 7.
Locate the Python packages installation directory in your system using the following command.
$ python -m site --user-siteYou should get a response similar to this.
C:\Users\<YOUR_USERNAME>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packagesModify the path response above by replacing the tail-end folder
site-packageswithScripts.C:\Users\<YOUR_USERNAME>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\ScriptsAdd the modified path to System Environment Variables.
Open the Start Menu and search for Environment Variables.
Select Edit the system environment variables.
On the Advanced tab in the System Properties window, click Environment Variables.

In the Environment Variables window, under System variables, find and select the
Pathvariable, then click Edit.In the Edit Environment Variable dialog, click New and paste the path to the Scripts directory (C:\Users\<YOUR_USERNAME>\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts).
Important: The above path is totally subjective to your system's PIP package install location; make sure you add the right path (from Step 5).
Click OK to close all dialog boxes.
Configure the package with the
config --setupflag.$ git-ai-commit config --setupWhen you run this command, you may encounter the error attached below. Skip the steps addressing the error if that is not the case and continue on Step 9.
Welcome to AI Commit MSG! Let's get you set up. [Setup] Git prepare-commit-msg hook Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts\git-ai-commit.exe\__main__.py", line 7, in <module> File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\main.py", line 154, in main config_handler(args) File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\config_handler.py", line 50, in config_handler handle_config_setup() File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\config_handler.py", line 9, in handle_config_setup onboarding_flow() File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\services\onboarding_service.py", line 81, in onboarding_flow setup_git_hook() File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\hook_handler.py", line 99, in setup_git_hook handle_setup_hook(file_path) File "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\hook_handler.py", line 56, in handle_setup_hook file.write(get_bash_script()) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2288.0_x64__qbz5n2kfra8p0\Lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'charmap' codec can't encode characters in position 273-274: character maps to <undefined>This UnicodeEncode error indicates that Python is trying to encode characters to a text file using an unsupported character-encoding format.
To address this error, open
hook_handler.pyfrom the file paths listed in the error message "C:\Users\USER_NAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\ai_commit_msg\cli\hook_handler.py"Locate the
handle_setup_hook(hook_directory_path: str)function and replace it with the following:... def handle_setup_hook(hook_directory_path: str): existing_hook_content = "" if os.path.exists(hook_directory_path): with open(hook_directory_path, "r", encoding='utf-8') as file: # Adds encoding='utf-8' to open() function to read the hook file existing_hook_content = file.read() if existing_hook_content == get_bash_script(): Logger().log("prepare-commit-msg hook already exists") return if existing_hook_content: override_content = input( f"prepare-commit-msg hook already exists in {hook_directory_path}\n\nWould you like to overwrite it? (y/n): " ) if override_content.lower() == "n": return elif override_content.lower() != "y": Logger().log("Invalid input. Exiting.") ## create the prepare-commit-msg file and write the hook code with open(hook_directory_path, "w", encoding='utf-8') as file: # Adds encoding='utf-8' to open() function to write to bash script file.write(get_bash_script()) # make the file executable os.chmod(hook_directory_path, 0o755) ...Note: ... indicates unchanged code.
Save the file.
This should fix the UniEncode error and let you proceed to choose your preferred LLM provider after you rerun the command
git-ai-commit config --setup.Select your preferred large language provider and model.
OpenAI and Anthropic each require an API key for LLM access - we'll use OpenAI.
To obtain an OpenAI API key, log in to OpenAI and create one.
Choose OpenAI and gpt-40-mini as your AI provider and model respectively, then enter the obtained API key. (other models require a paid subscription).
Welcome to AI Commit MSG! Let's get you set up. [Setup] Git prepare-commit-msg hook prepare-commit-msg hook already exists in .git/hooks/prepare-commit-msg Would you like to overwrite it? (y/n): n Choose your preferred AI provider: [?] Select AI Provider: > OpenAI Anthropic Ollama [?] Select Model: gpt-4-0125-preview gpt-4-turbo-preview gpt-4-vision-preview gpt-4-1106-vision-preview gpt-4-turbo gpt-4-turbo-2024-04-09 gpt-4-32k gpt-4-32k-0314 gpt-4-32k-0613 gpt-4o gpt-4o-2024-05-13 > gpt-4o-mini gpt-4o-mini-2024-07-18 Let's set up your Openai API key. [?] Enter your Openai API key: sk-XXXXXXXXXXXOn successful API key entry, you'll be asked to enable event logging feature. Confirm (y) or decline (N) to complete setup.

Run config command to view configuration settings.
$ git-ai-commit configSettings ---------------------- Anthropic Api Key: Openai Api Key: sk-proj-...154j Logger Enabled: True Model: gpt-4o-mini Ollama Url: http://localhost:11434/api/chat Last Updated At: 2024-12-23 13:26:54 Max Length: 50Finally, stage file changes and generate commit message.
$ git add . $ git-ai-commit summarizeBelow is an example response from GPT-4o-mini assuming the API key provided is valid:
Fetching your staged changes... Here is a summary of your changes: added ai-generated commit message guidelines document to use this summary run: `git commit -m "added ai-generated commit message guidelines document"`
All git-ai-commit configuration options and their implementation are outlined in this documentation.
Limitations
git-ai-commit usage is only limited by your API key and subscription rate limit. For example, Open AI restricts free-tier accounts API use to 40,000 - 60,000 tokens per minute and 200 requests per day. You can increase this limit by buying OpenAI credits or upgrading your account.
Recommendations
Aside the seemingly unstable nature of the package, which results in an avoidably lengthy setup process, it is a more versatile AI commit message tool considering the variety of model options it supports.
Auto Git Commit (autogitc)
autogitc is a Ruby package built by Adrian Goh Jon Wei to help developers write clear and consistent commit messages. It uses GPT-4o-Mini which is OpenAI's most cost-effective model.
Installation and Setup
To use autogitc in your project, follow these steps.
Visit rubyinstaller.org to download and install Ruby or use OS installation packages.
For Windows
$ choco install rubyFor macOS
$ brew install rubyVerify package installation.
$ ruby -vInstall Gem bundler (not mandatory).
$ gem install bundlerNote: You may have to restart your IDE and terminal to integrate Ruby and gem bundler installations.
Install
autogitcwith the Gem package installer.$ gem install autogitcSet
AUTOGITC_KEYkey as the API key obtained from OpenAI in your system environment variables.You can do this easily in the PowerShell terminal using the following command. (replace the placeholder with your key - retain apostrophes)
$ [System.Environment]::SetEnvironmentVariable('AUTOGITC_KEY', 'your_openai_api_key_here', [System.EnvironmentVariableTarget]::User)Verify environment variable addition.
$ Get-ChildItem Env:AUTOGITC_KEYYou should see your API key returned in the terminal.
You can also verify or set the key via the system environment variables window.

Stage file changes, then run autogitc to automatically generate commit message and commit changes.
$ git add .
$ autogitc
For reviewability purposes, it is recommended that you use the --nc (or --nocommit) flag instead to generate commit messages.
$ autogitc --nc
You should get a successful response that looks like this:
Running autogitc...
Generated commit message:
Add AI-Generated GIT Commit guidelines and API key image
N/B: You can also add the --text=XXX flag to indicate specific text(s) that must be included in the commit message. Replace XXX with the text you wish to include.
Review commit message suggestions and make changes (where necessary) to be more precise.
Limitations
As mentioned earlier, with autogitc you're restricted to just one LLM model, which is Gpt-4o-mini, unlike Copilot and git-ai-commit offering multiple LLM provider options.
Recommendation
autogitc is a great choice if you want to try a quick, straightforward third-party option, with only one configuration requirement: your OpenAI API key.
Conclusion
In ~10 minutes, you’ve learned to use AI tools to ease and refine your project’s version documentation process.
We've covered three options that analyze code changes to produce contextual commit messages and provided practical steps for adopting them.
While these tools do not eliminate your responsibility of ensuring that commit messages are clear, informative, and relevant, they help maintain conventional commit standards and offer solid starting points.
Go make your project's story better, one commit message at a time.



