AIGitCommit
is a command-line tool that generates meaningful, semantic commit messages from your staged Git changes using AI.
It inspects your diffs, summarizes the intent of your changes, and produces clear, concise commit messages that follow the Conventional Commits specification.
- https://www.conventionalcommits.org/en/v1.0.0/
- https://nitayneeman.com/blog/understanding-semantic-commit-messages-using-git-and-angular/
- https://ssshooter.com/2020-09-30-commit-message/
- Generates meaningful, semantic commit messages from staged changes.
- Commit directly to the repository with the
--commit
flag or copy the generated message with--copy
. - Output formats: human-readable text, JSON (machine-readable) and table view. JSON output is useful for CI integrations and automation; table view makes it easy to scan multiple suggested lines.
- Easy-to-use command-line interface with sensible defaults and confirm prompts (can be skipped with
--yes
). - Uses libgit2 via the
git2
crate, avoiding external git commands for improved security and performance. - Supports multiple OpenAI-compatible models and configurable API base, token, and proxy settings.
- Optional auto sign-off of commits when
GIT_AUTO_SIGNOFF=true
. - Proxy support: HTTP and SOCKS5 (set via
OPENAI_API_PROXY
).
AIGitCommit inspects your staged Git changes, summarizes the intent of those changes, and generates clear semantic commit messages. It examines diffs and uses an AI model to infer intent and produce concise, useful commit lines.
AIGitCommit is still in the early stages of development, I suggest you to install it using the git URL using the commands below:
cargo install --git https://github.com/mingcheng/aigitcommit.git
or, You can install from crates.io
cargo install aigitcommit
Those command will auto-download the latest version of the project and install it to your cargo bin directory.
AIGitCommit can run in Docker if you prefer not to install the binary locally. Example (read-only repository):
docker run \
--rm \
-v $PWD:/repo:ro \
-e OPENAI_API_BASE='<api base>' \
-e OPENAI_API_TOKEN='<api token>' \
-e OPENAI_MODEL_NAME='<model name>' \
-e OPENAI_API_PROXY='<proxy if needed>' \
ghcr.io/mingcheng/aigitcommit
If you want to use --commit
from inside the container, mount the repo as writable and run interactively:
docker run \
--rm \
-it \
-v $PWD:/repo:rw \
-e OPENAI_API_BASE='<api base>' \
-e OPENAI_API_TOKEN='<api token>' \
-e OPENAI_MODEL_NAME='<model name>' \
-e OPENAI_API_PROXY='<proxy if needed>' \
ghcr.io/mingcheng/aigitcommit --commit
Use --yes
to skip interactive confirmations.
AIGitCommit ships a hooks/prepare-commit-msg
hook you can copy into a repository's .git/hooks/prepare-commit-msg
to automatically generate commit messages during git commit
.
To install globally:
mkdir -p ~/.git-hooks
# copy the file from this project into ~/.git-hooks/prepare-commit-msg
chmod +x ~/.git-hooks/prepare-commit-msg
git config --global core.hooksPath ~/.git-hooks
After installing the hook, git commit
will run the hook and populate the commit message. Use --no-verify
to bypass hooks when necessary.
Before using AIGitCommit, export the following environment variables (for example in your shell profile):
OPENAI_API_TOKEN
: Your OpenAI-compatible API token.OPENAI_API_BASE
: The API base URL (useful for alternative providers or local proxies).OPENAI_MODEL_NAME
: The model name to query (e.g., a GPT-compatible model).OPENAI_API_PROXY
: Optional. Proxy address for network access (e.g.,http://127.0.0.1:1080
orsocks://127.0.0.1:1086
).GIT_AUTO_SIGNOFF
: Optional. Set totrue
to append a Signed-off-by line to commits.
After setting the environment variables, you can check if they are set correctly by running:
aigitcommit --check-env
This will print the current configuration and verify that the required variables are set.
Then you can run
aigitcommit --check-model
to check if the specified model is available and can be queried successfully.
You can also run aigitcommit --help
to see the available options and usage instructions.
Run aigitcommit
in a repository with staged changes. Optionally provide a path to the git directory: aigitcommit <dir>
.
Common flags:
--commit
commit generated message directly to the repository.--copy-to-clipboard
copy the generated message to the clipboard.--json
print the suggestions as JSON for CI or automation.--yes
skip confirmation prompts and apply the default action.--signoff
append a Signed-off-by line to the commit message.
See aigitcommit --help
for the full list of options.
This project is licensed under the MIT License. See the LICENSE
file for details.