Skip to content

A CLI tool that helps you write better Git commit messages using OpenAI's GPT-4 language model.

Notifications You must be signed in to change notification settings

Fulviuus/git-commit-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Git Commit Message Generator

This script generates a Git commit message based on a diff using OpenAI's GPT-4. It uses Deno for running the script.

Screencast

Prerequisites

Installation

  1. Clone this repository:
git clone https://github.com/Flviuus/git-commit-generator 
cd git-commit-generator 
  1. Create a .env file in the root directory of the project and add your OpenAI API key and configuration:
OPENAI_API_KEY=your_openai_api_key_here
MODEL_VERSION=gpt-4
NUM_COMMIT_MESSAGES=3

Usage

Run the script in a Git repository to generate a commit message based on the current diff:

deno run --allow-net --allow-read --allow-run --allow-env main.ts

You can also specify a directory where the Git repository is located:

deno run --allow-net --allow-read --allow-run --allow-env main.ts -d /path/to/your/repo

Options

  • -h, --help: Show the help message and exit
  • -d, --dir: Directory where to perform the diff (default: current directory)
  • --debug: Show debug information

Running the script globally using an alias in .bashrc

To run the script globally on your system, you can add an alias in your .bashrc file.

  1. Open your .bashrc file located in your home directory:
nano ~/.bashrc
  1. Add the following line to the end of the file, replacing /path/to/your-repo/main.ts with the actual path to the main.ts file in your repository:
alias commitgen='deno run --allow-net --allow-read --allow-run --allow-env /path/to/your-repo/main.ts'
  1. Add the following environment variables to the file:
export OPENAI_API_KEY=yout_openai_api_key_here
export MODEL_VERSION=gpt-4
export NUM_COMMIT_MESSAGES=3
  1. Save the file and exit the editor.

  2. Reload your .bashrc file by running:

source ~/.bashrc

Now you can use the commitgen command from any directory to generate a commit message based on the current diff:

commitgen

If you want to specify a directory where the Git repository is located, you can still use the -d option:

commitgen -d /path/to/your/repo

Compiling the script

You can also compile the Deno script into a standalone executable binary, so you don't need to run it through the Deno runtime.

  1. Compile the script:
deno compile --allow-net --allow-read --allow-run --allow-env -o commitgen main.ts

This will create a binary called commitgen.

  1. Move the binary to a directory in your $PATH, like /usr/local/bin:
sudo mv commitgen /usr/local/bin/
  1. Make sure the binary is executable:
sudo chmod +x /usr/local/bin/commitgen
  1. Add the following environment variables to your .bashrc file:
export OPENAI_API_KEY=yout_openai_api_key_here
export MODEL_VERSION=gpt-4
export NUM_COMMIT_MESSAGES=3

Now you can use the commitgen command from any directory to generate a commit message based on the current diff:

commitgen

If you want to specify a directory where the Git repository is located, you can still use the -d option:

commitgen -d /path/to/your/repo

License

This code is licensed under the MIT License.

About

A CLI tool that helps you write better Git commit messages using OpenAI's GPT-4 language model.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published