git-cli
A CLI tool that translates natural-language task descriptions into git (and GitHub CLI) commands using a local Ollama LLM.
Works in any terminal — IntelliJ, Cursor, VS Code, and others.
Features
- Dual model routing — simple tasks use a fast small model, complex tasks auto-switch to a smarter model
- GitHub CLI support — generates
ghcommands for PRs, merges, and repo operations - Safety checks — destructive commands are blocked unless
--forceis passed; shell injection is always blocked - Smart parsing — handles multi-line LLM output, strips markdown, auto-fixes case/esac glob patterns
Prerequisites
- Ollama running locally with models pulled
# Pull the default models
Installation
# From crates.io
# From source
Usage
# Describe what you want — git-cli prints the commands
# Add --execute (-x) to run the commands immediately
# Use --force for destructive commands
# Override the model for a single invocation
# Show the full prompt sent to the LLM
# See all example tasks
Smart Model Routing
Tasks are automatically classified as simple or complex:
# Simple tasks → fast model (qwen2.5:3b)
# Complex tasks → smart model (auto-detected)
The output shows which model was selected:
● Asking qwen2.5:3b (simple → fast model) for git commands...
● Asking qwen2.5:3b (complex → smart model) for git commands...
GitHub CLI Support
git-cli can also generate gh commands for GitHub operations:
Safety
Destructive commands (push --force, reset --hard, clean -f, branch -D, filter-branch) are highlighted in red and blocked unless you pass --force:
Commands containing shell injection patterns (&&, |, ;, $()) outside of quoted strings are always blocked.
Configuration
Settings are stored in ~/.git-cli.toml:
# View current settings
# Set a custom Ollama endpoint
Example ~/.git-cli.toml:
= "qwen2.5:3b"
= "qwen2.5:3b"
= "http://localhost:11434"
= "10m"
[]
= "undo my last commit but keep changes"
= "push and set upstream"
CLI flags (--model, --endpoint) override the config file. --model overrides both fast and smart for that invocation.
Prompt Customization
You can customize the system prompt sent to the LLM via ~/.config/git-cli/prompt.toml. Scaffold a starter file:
The prompt is built in three layers:
| Layer | Location | Overridable? |
|---|---|---|
| Preamble | prompt.toml → preamble |
Yes — replace the default role/rules text |
| Safety rules | Embedded in binary | No — always appended (PR rules, rebase -i blocking, branch lifecycle) |
| Examples | prompt.toml → [[examples]] |
Additive — your examples are appended after the built-in ones |
Example ~/.config/git-cli/prompt.toml:
# Replace the default preamble (optional)
# preamble = "You are a senior DevOps engineer..."
# Add custom few-shot examples
[[]]
= "tag the current commit as v1.0.0"
= """
# Create an annotated tag
git tag -a v1.0.0 -m "Release v1.0.0"
# Push the tag to remote
git push origin v1.0.0"""
[[]]
= "show the diff between main and develop"
= """
# Compare main and develop branches
git diff main..develop"""
If the file doesn't exist, the built-in defaults are used — no configuration required.
Aliases
Define shortcuts in ~/.git-cli.toml to save typing:
[]
= "undo my last commit but keep changes"
= "squash last 3 commits"
= "push and set upstream"
Then run git-cli undo instead of the full description.
Shell Completions
# Bash
# Zsh
# Fish
How It Works
- Checks for an alias match in your config.
- Gathers context from the current git repo (branch, status, recent log, remotes).
- Classifies the task as simple or complex and selects the appropriate model.
- Builds a system prompt with rules and few-shot examples, plus a user prompt with repo context.
- Sends the prompt to the local Ollama chat API.
- Parses the response: joins multi-line commands, strips markdown, auto-fixes case/esac globs.
- Validates commands: blocks injection, checks HEAD~N against actual commit count, flags destructive ops.
- Displays commands with syntax highlighting.
- With
--execute, runs each command sequentially.
License
MIT