An AI-powered Git commit message generator written in Rust that automatically stages your changes and creates Conventional Commit messages using the OpenAI API.
git-cmt-rs automatically stages all changes with git add ., analyzes the diff, and generates meaningful commit messages using OpenAI's chat completion models. It follows the Conventional Commits specification and provides an interactive commit experience with editor review.
Feel free to tweak the code to try different models, providers, or prompt templates. The implementation is simple and hackable.
This project is a Rust implementation of the Go based git-cmd project found here
- π€ AI-powered: Uses OpenAI models (default:
gpt-4.1-mini) to analyze code changes - π Conventional Commits: Generates messages in the
type(scope): descriptionformat - π― Smart Analysis: Understands code changes and suggests contextually appropriate messages
- β Push Confirmation: Asks for y/n confirmation before pushing to remote
- β‘ Interactive: Opens your editor for final review and editing before committing
- π¦ Auto-staging: Automatically stages all changes with
git add .before analysis - π Diff-aware: Analyzes changes to generate contextually appropriate messages
- π Length-aware: Keeps commit messages concise (50 chars max for description)
- Rust (1.70+ recommended)
- Git
- An OpenAI API key
git clone https://github.com/AaronSaikovski/git-cmt-rs
cd git-cmt-rs
cargo build --release# Move binary to a directory in your PATH
sudo mv target/release/git-cmt-rs /usr/local/bin/git-cmt-rs- Set your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here" or $env:export OPENAI_API_KEY="your-api-key-here"
- (Optional) Override model or base URL:
export OPENAI_MODEL="gpt-4.1-mini" export OPENAI_BASE_URL="https://api.openai.com/v1"
- Run the tool (stages all changes automatically):
git-cmt-rs
- The editor opens for final review and editing of the commit message.
- Save and close the editor to create the commit.
- After commit, confirm whether to push to remote (y/n).
- If confirmed, changes are pushed; if declined, commit stays local.
The tool automatically stages all changes with git add . before analyzing and generating a commit message.
- Auto-staging: Stages all changes with
git add . - Diff Analysis: Reads staged changes with
git diff --cached -b(truncated to 3072 chars if necessary) - AI Processing: Sends the diff to OpenAI with structured prompts and JSON schema enforcement
- Message Generation: Produces a commit object with
type,scope, andmessage - Interactive Commit: Opens your editor with the message for final review and editing
- Create Commit: Runs
git commitwith the approved message - Push Confirmation: Asks user to confirm push to remote (y/n)
- Final Push: Runs
git pushif confirmed, or exits with commit saved locally if declined
type(scope): description
- Types: feat, fix, docs, style, refactor, test, chore
- Scope: Optional component/module name
- Description: Clear, concise summary (max 50 chars)
$ git-cmt-rs
Staged all changes with `git add .`
Staged diff found; generating message for changes...
Parsed commit: type='feat', scope='auth', message='add OAuth2 login integration'
# Opens editor for final review
# Save and close editor to commit
Commit created successfully.
Push commit to remote? (y/n): y
Changes pushed successfully!$ git-cmt-rs
Staged all changes with `git add .`
Staged diff found; generating message for changes...
Parsed commit: type='fix', scope='api', message='resolve null pointer in validation'
# Opens editor for final review
# Save and close editor to commit
Commit created successfully.
Push commit to remote? (y/n): n
Push cancelled. Commit saved locally.Users can respond with n or no at the push confirmation to keep the commit local without pushing to remote:
$ git-cmt-rs
Staged all changes with `git add .`
...
Commit created successfully.
Push commit to remote? (y/n): n
Push cancelled. Commit saved locally.OPENAI_API_KEYβ required for API accessOPENAI_MODELβ model to use (default:gpt-4.1-mini)OPENAI_BASE_URLβ API endpoint (default:https://api.openai.com/v1)EDITORβ editor for reviewing commits (defaults to system default)
- Failed to stage changes β exits if
git add .fails - No staged changes β exits with helpful message if no changes exist
- Missing API key β exits with message to set
OPENAI_API_KEY - API failures β shows HTTP status and response body
- Invalid JSON β shows raw model output for debugging
- Commit creation failed β exits with error message if
git commitfails - Push declined β exits gracefully with "Push cancelled. Commit saved locally." when user responds with
norno - Push failed β shows error if
git pushfails (commit is already saved locally) - Invalid push confirmation input β prompts user to answer
y/nagain
reqwestβ HTTP clientserde/serde_jsonβ JSON parsingtokioβ async runtimeanyhowβ error handling
βββ src/main.rs # Core logic
βββ Cargo.toml # Dependencies and metadata
βββ README.md # This file
cargo buildThis project is open source. See the repository for details.
"No staged changes found"
- This occurs when there are no modified files in your working directory. Make sure you have uncommitted changes before running
git-cmt-rs.
"OPENAI_API_KEY not set"
- Export your OpenAI API key.
"OpenAI request failed"
- Check your internet connection.
- Verify your API key.
- Ensure your account has credits and API access.
Editor not opening
- Set your editor explicitly:
export EDITOR="code --wait"
"Push cancelled. Commit saved locally." message
- This is expected behavior. The user can respond
nornoat the push confirmation prompt to keep the commit local. - The commit is already created and saved; the push is simply skipped.
- You can push manually later with
git push.
"Push failed" error
- The commit was created successfully, but the push to remote failed (network issues, authentication, etc.)
- Your commit is safely saved locally
- You can try pushing again manually or resolve any issues before retrying