git-msg is a Git helper tool.
Its main function is to automatically generate commit messages that conform to the Conventional Commits specification, complete with appropriate emojis, by analyzing the current repository's diff and calling a large model API. It supports interactive confirmation, staging area management, and custom prompt templates.
According to the library's documentation, the interactive interface may have issues on Windows.
- Automatically retrieves diffs from the Git working directory or staging area.
- Calls a large model (compatible with OpenAI API format) to generate commit messages.
- Generated commit message format:
<emoji> <type>(<scope>): <description>(e.g.,🔬 test(cli.go): add new command line feature -t). - Interactively asks whether to add unstaged files and whether to commit.
- Supports custom prompts (via Markdown files in the
skill/directory). - Can specify a custom Git command (e.g.,
yadm).
Ensure Go 1.26+ is installed, then execute:
git clone https://github.com/conglinyizhi/git-msg.git
cd git-msg
go build -o git-msgPlace the generated git-msg binary in your PATH, e.g., ~/.local/bin.
install -Dm755 git-msg ~/.local/bin/git-msg requires configuration of the large model's API information. There are two ways to configure it (in order of priority, highest first):
-
Configuration File (recommended):
The tool creates allm.tomlfile in the system's standard configuration directory:- Linux:
~/.config/git-msg/llm.toml - macOS:
~/Library/Preferences/git-msg/llm.toml - Windows:
%LOCALAPPDATA%\git-msg\Config\llm.toml
You can also use
git-msg initto quickly create the configuration file, which will also copy the built-in skills to the designated skill directory.Example file content:
API_KEY = "your-api-key" BASE_URL = "https://api.openai.com/v1/chat/completions" MODEL_NAME = "gpt-3.5-turbo"
- Linux:
-
Environment Variables:
API_KEY: API keyBASE_URL: API endpointMODEL_NAME: model name
For example:
export API_KEY="your-api-key" export BASE_URL="https://api.openai.com/v1/chat/completions" export MODEL_NAME="gpt-3.5-turbo"
Simply run the tool inside a Git repository:
git-msgThe tool will automatically perform the following steps:
- Read the configuration (file or environment variables).
- Retrieve the Git diff (prioritizes the staging area; if empty, falls back to the working directory).
- Call the large model to generate a commit message (printing the generation process in real-time).
- Interactively ask:
- If there are unstaged files, it will ask whether to add them, view the status, or exit.
- Finally, it will ask whether to execute
git commit.
- If the user confirms, it executes the corresponding Git command and outputs the result.
-g, --git <command>: Specify the Git command path or alias (defaultgit). Useful for replacing it with other Git-compatible tools likeyadm.-l, --loop <number>: Send multiple requests simultaneously (default 1) to generate multiple commit messages for selection, making it easier to choose the most appropriate one.--ping: Test the configured large model API with a minimal prompt to verify connectivity.
Example:
git-msg init
git-msg -g yadm
git-msg -l 3 # Generate 3 commit messages simultaneously for selectionThe tool uses Markdown files in the skill/ directory as system prompts. You can place multiple .md files; during runtime, you will be prompted to select one. If only one file exists, it will be used automatically.
Example directory structure:
./skill/
├── default.md
├── detailed.md
└── emoji-only.md
Skill files use Markdown format. Note: The header section of the file (such as YAML frontmatter) is currently not processed specially; all content in the file is embedded directly into the system prompt.
It is recommended to keep skill file content in plain text prompt format.
Issues and Pull Requests are welcome. Please ensure code style is consistent and tests pass.
MIT License
This tool uses the following excellent open-source libraries:
- go-toml (MIT)
- pflag (BSD-3)
- promptkit (MIT)
- cloudwego/eino (Apache-2.0)