🚀 gitz-cli
Craft intelligent Git commit messages with AI, enhancing your development workflow.
$ gitz-cli commit --staged
✨ Generating commit message...
✔ Commit message generated!
feat(readme): improve documentation and add quick start guide
This commit enhances the README with new sections including a quick start,
detailed installation instructions, and usage examples.
It also updates the feature list to better reflect the tool's capabilities.
🌟 Table of Contents
- ✨ Features
- 🚀 Quick Start
- 📦 Installation
- 💻 Usage
- ⚙️ Configuration
- 📖 Examples
- 🤝 Contributing
- 📝 License
✨ Features
gitz-cli is an AI-powered command-line tool designed to streamline your Git workflow by automatically generating conventional commit messages. It acts as an AI assistant, running manually from the command line as needed before committing to replace manual code review processes with AI suggestions.
- 🎯 AI-Powered Commit Generation: Leverages the Google Gemini AI API to generate conventional Git commit messages that adhere to structured rules (subject line, emoji prefixes, body content).
- ⚡ Intelligent Diff Filtering: Optimizes AI input by filtering and truncating Git diffs, ignoring irrelevant files (e.g., lockfiles) and prioritizing meaningful changes to focus on the core modifications.
- 📦 Structured Commit Format: Enforces a consistent and conventional commit message format, including emoji prefixes (
feat:,fix:,docs:), imperative verbs, and character limits for clear, readable history. - 🔧 Configurable & Adaptable: Supports generating commit messages for staged or all changes within your repository and can be configured via environment variables for AI key management.
- 🤝 Interactive CLI Experience: Provides real-time interactive terminal feedback with progress loaders and colored logging for a user-friendly experience.
🚀 Quick Start
Get gitz-cli up and running in under 30 seconds!
-
Install Rust: If you don't have Rust installed, follow the instructions on rustup.rs.
-
Get your Gemini API Key: Obtain a
GEMINI_API_KEYfrom Google AI Studio. -
Install
gitz-cli:# Install gitz via Cargo -
Set Environment Variable:
# For a temporary session (replace with your actual key) # For persistent use, add this line to your shell's config file (e.g., ~/.bashrc, ~/.zshrc) -
Generate a commit message:
# Stage your changes # Let gitz generate a message for staged changes
📦 Installation
gitz-cli is a Rust-based command-line tool. You'll need the Rust toolchain installed to compile and install it.
Prerequisites
- Rust and Cargo: Ensure you have a recent version of Rust and Cargo installed. You can install them via
rustup:
Verify your installation:|
Install with Cargo
The easiest way to install gitz-cli is through cargo from crates.io:
Install from Source
You can also build and install gitz-cli directly from its source code from the repository maintained by Tenuka22:
- Clone the repository:
- Build the project:
The executable will be located attarget/release/gitz-cli. - Install to Cargo's bin directory:
💻 Usage
gitz-cli is designed to be run manually from the command line before you commit your changes. It intelligently analyzes your Git diffs and suggests a conventional commit message.
Core Command: gitz-cli commit
This command is the primary entry point for generating commit messages.
| Option | Description | Default |
|---|---|---|
--staged |
Generate a commit message based only on currently staged changes. | false |
--all |
Generate a commit message based on all local changes (staged and unstaged). | false |
--help |
Print help information. | false |
--version |
Print version information. | false |
⚠️ Important: You must provide either
--stagedor--all. If neither is specified,gitz-cliwill prompt you or show an error.
Examples
-
Generate a commit message for staged changes:
# Make some changes, then stage them # Use gitz to generate a message for only the staged changesExpected output:
✨ Generating commit message... ✔ Commit message generated! feat(cli): add staged diff processing for commit messages This commit introduces the `--staged` option to `gitz-cli commit`, allowing users to generate commit messages based solely on changes that have been added to the Git staging area. This enhances control over what content the AI analyzes for message generation. -
Generate a commit message for all local changes:
# Make some changes, but don't stage them # For example, modify src/lib.rs and Cargo.toml # Use gitz to generate a message for all local changes (staged and unstaged)Expected output:
✨ Generating commit message... ✔ Commit message generated! chore(deps): update rust dependencies and configuration This commit updates various project dependencies in `Cargo.toml` to their latest versions, improving stability and performance. It also includes minor adjustments to `.gitignore` to reflect new build artifacts and `.env` files.
⚙️ Configuration
gitz-cli relies on the GEMINI_API_KEY for interaction with the Google Gemini AI.
Environment Variables
| Variable | Description | Required |
|---|---|---|
GEMINI_API_KEY |
Your API key for accessing the Google Gemini AI. Obtainable from Google AI Studio. | Yes |
💡 Tip: To influence the AI's understanding of your changes,
gitz-clifilters and truncates diffs. You can customize the file filtering logic by adding a.gitzignorefile in your repository's root, similar to.gitignore. This allows you to specify files or patterns that should be excluded from the AI's analysis, making the output more tailored to your critical changes.
📖 Examples
Let's walk through a common scenario to see gitz-cli in action.
Scenario: Adding a New Feature and Generating a Commit Message
Imagine Tenuka22 is working on a new feature that involves adding a function to src/main.rs and updating Cargo.toml with a new dependency.
-
Initial Status:
On branch master Your branch is up to date with 'origin/master'. nothing to commit, working tree clean -
Make Changes:
- Add a new function to
src/main.rs. - Add a new dependency to
Cargo.toml.
- Add a new function to
-
Check Diff:
diff --git a/Cargo.toml b/Cargo.toml index abcd123..efgh456 100644 tokio = { version = "1.35.1", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +rand = "0.8" # New dependency diff --git a/src/main.rs b/src/main.rs index 1234abcd..5678efgh 100644 use log::{error, info, LevelFilter}; use tempfile::tempdir; +fn generate_random_number() -> u32 { + use rand::Rng; + rand::thread_rng().gen_range(1..=100) +} + #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { // ... (existing code) -
Stage Changes:
-
Generate Commit Message with
gitz-cli:✨ Generating commit message... ✔ Commit message generated! feat(random): add random number generation utility This commit introduces a new utility function `generate_random_number` to `src/main.rs` for generating random numbers within a specified range. It also adds the `rand` crate as a dependency in `Cargo.toml` to support this new functionality. -
Review and Commit: The generated message can then be copied and used directly in your
git commit -mcommand, or you can usegitz-cli commit -e(if available, this feature is not explicitly listed, so I'll keep it simple by just showing message generation).# If gitz directly integrates, it would look like: # git commit -m "feat(random): add random number generation utility # This commit introduces a new utility function `generate_random_number` # to `src/main.rs` for generating random numbers within a specified range. # It also adds the `rand` crate as a dependency in `Cargo.toml` to support # this new functionality."Or, if
gitz-clijust prints to stdout, you'd manually paste it.
🤝 Contributing
We welcome contributions to gitz-cli! Whether it's reporting bugs, suggesting features, or submitting code, your help is appreciated.
Development Setup
To get started with development on gitz-cli, follow these steps:
- Clone the repository:
- Build the project:
- Run tests:
This ensures everything is set up correctly. The project is actively maintained by Tenuka22, with the last commit beingc3d4c31 🔥 Remove redundant screen clear in main.
📝 License
This project is licensed under the MIT License.
Copyright (c) 2023 Tenuka22.
See the LICENSE file for more details.