🚀 gitz-cli
Craft intelligent Git commit messages with AI, enhancing your development workflow.
$ gitz-cli commit stage
✨ 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 com…
🚀 gitz-cli
Craft intelligent Git commit messages with AI, enhancing your development workflow.
$ gitz-cli commit stage
✨ 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. 1.
Get your Gemini API Key: Obtain a GEMINI_API_KEY from Google AI Studio.
1.
Install gitz-cli:
# Install gitz via Cargo
cargo install gitz-cli
Set Environment Variable:
# For a temporary session (replace with your actual key)
export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
# For persistent use, add this line to your shell's config file (e.g., ~/.bashrc, ~/.zshrc)
echo 'export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"' >> ~/.bashrc # or ~/.zshrc
source ~/.bashrc # or ~/.zshrc
Generate a commit message:
# Stage your changes
git add .
# Let gitz generate a message for staged changes
gitz-cli commit stage
📦 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:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Verify your installation:
rustc --version # Example: rustc 1.70.0 (90c541806 2023-05-31)
cargo --version # Example: cargo 1.70.0 (106af7b60 2023-06-02)
Install with Cargo
The easiest way to install gitz-cli is through cargo from crates.io:
cargo install gitz-cli
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:
git clone https://github.com/Tenuka22/gitz.git
cd gitz
- Build the project:
cargo build --release
The executable will be located at target/release/gitz-cli.
- Install to Cargo’s bin directory:
cargo install --path .
💻 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 |
|---|---|---|
stage | Generate a commit message based only on currently staged changes. | false |
any | 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
stageorany. 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
git add src/main.rs
# Use gitz to generate a message for only the staged changes
gitz-cli commit stage
Expected output:
✨ Generating commit message...
✔ Commit message generated!
feat(cli): add staged diff processing for commit messages
This commit introduces the `stage` 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)
gitz-cli commit any
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:
git 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.
Check Diff:
git diff
diff --git a/Cargo.toml b/Cargo.toml
index abcd123..efgh456 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,3 +10,4 @@
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
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,6 +5,11 @@
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:
git add .
Generate Commit Message with gitz-cli:
gitz-cli commit stage
✨ 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 -m command, or you can use gitz-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-cli just 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:
git clone https://github.com/Tenuka22/gitz.git
cd gitz
- Build the project:
cargo build
- Run tests:
cargo test
This ensures everything is set up correctly. The project is actively maintained by Tenuka22, with the last commit being c3d4c31 🔥 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.