git-gpt is a ruby gem that adds an additional git subcommand, git gpt. It assists you in creating commit messages for your git changes. It uses the powerful capabilities of ChatGPT to generate commit messages based on the current git status and git diff. Additionally, you can specify a list of files to narrow down the context for the commit message.
First, you need to install the gem. You can do this globally or in your specific Ruby environment.
gem install git-gpt
Once installed, it will be accessible as a git subcommand.
You can invoke the git gpt
command in your terminal anywhere in your git repository:
git gpt
This will return a commit message generated by ChatGPT based on the changes detected by git status
and git diff
.
If you wish to narrow down the context to a specific list of files, you can do so by passing them as arguments:
git gpt file1 file2 file3
In the above example, file1
, file2
, and file3
are placeholders for the file names you want to focus on. This will generate a commit message based on the changes in those files only.
git gpt
does not actually commit your code, it simply prints a commit message that you can choose to use or not. If you run it multiple times, you will likely get different results.
By default it asks ChatGPT to create longer messages with bullet points for each file with significant changes. I recommend setting GIT_EDITOR=vim
and pasting your commit messages into the editor. If you like shorter or single line messages, you can adjust your prompt to something like the following (see Advanced Configuration below):
Please write a commit message for this change. The commit message should be a single sentence. The commit message should start with a capital letter. The commit message should end with a period. The commit message should be 50 characters or less.
Best practice is to set the OPENAI_API_KEY
environment veriable. Optionally, you can set OPENAI_ORGANIZATION_ID
.
By default git gpt
uses gpt-3.5-turbo
with a temperature of 0.7
. You can find the default prompt here. If you'd like to change the default settings, you can add a .git-gpt-config.yml
file in your git repository. git-gpt
will look for that file in the current directory, any parent directory (all the way to /
) and your HOME
directory. It will look in that order and use the first one it finds. The structure of the YAML file is as follows, all keys are optional.
model: gpt-4
temperature: 0.8
openai_api_key: sk-acb1234567890xyz
openai_organization_id: org-abc1234567890xyz
prompt: >
You are a software engineer working on a project. You write diligent and detailed commit messages. You are working on a new feature and you are ready to commit your changes.
The current git status is:
$GIT_STATUS
The current git diff is:
$GIT_DIFF
Please write a commit message for this change. Format the commit message using markdown. You may use bullet points. Please comment specifically on any files with significant changes.
See a real example here.
Bug reports and pull requests are welcome on GitHub at https://github.com/assaydepot/git-gpt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.