Skip to content
/ git-ai Public

Git auto-stage changes and generate a commit message from the diff

Notifications You must be signed in to change notification settings

preynal/git-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git ai

Stage all changes and generate a commit message using LLMs (gpt-4o-mini) in one command.

What it does:

git add . && git diff --staged | english | git commit -F -

Features

  • Generates clear and concise commit messages following conventional commits format
  • Automatically analyzes staged git changes
  • Configurable file exclusions
  • Token counting and cost estimation

Installation

  1. Clone the repository:
git clone https://github.com/preynal/git-ai
cd ./git-ai
  1. Install dependencies:
yarn
# or
npm install
  1. Configure OpenAI API key: Create a .env file in the root directory:
OPENAI_API_KEY=your-api-key

Recommended Usage

Add a git ai alias to your ~/.gitconfig file:

[alias]
	ai = "!node <PATH_TO_CLONED_DIR>/git-ai.js"

Then in any git reposoritory, you can run:

git ai

It will add all changes to the staging area, generate a commit message, and you can approve it by pressing Enter.

Configuration

The tool can be configured through src/config.js:

  • systemMessage: Custom prompt for the AI
  • excludedFiles: Array of files to exclude from the diff analysis
  • modelName: GPT model to use
  • pricePerMillionTokens: OpenAI API pricing configuration

Requirements

  • Tested on Node.js 22 LTS
  • Git
  • OpenAI API key

License

MIT

About

Git auto-stage changes and generate a commit message from the diff

Resources

Stars

Watchers

Forks