|
Some checks failed
Test And Tag / check-version (push) Failing after 5s
Test And Tag / test (push) Has been skipped
Test And Tag / lint (push) Has been skipped
Test And Tag / build (push) Has been skipped
Test And Tag / build-nix (push) Has been skipped
Test And Tag / semver (push) Has been skipped
Test And Tag / test-integration (push) Has been skipped
|
||
|---|---|---|
| .forgejo | ||
| .gitlab | ||
| commitlint | ||
| config | ||
| docs/themes | ||
| generate | ||
| gitmoji | ||
| openai | ||
| prompt | ||
| rebase | ||
| types | ||
| ui | ||
| vcs | ||
| .fast-commit.example.toml | ||
| .gitignore | ||
| .goreleaser.yaml | ||
| flake.lock | ||
| flake.nix | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| main.go | ||
| main_test.go | ||
| PLAN.md | ||
| README.md | ||
| ROADMAP.md | ||
Fast-Commit
A Go CLI application that generates intelligent commit messages using OpenAI's API. It analyzes git diffs and creates contextual commit messages, then prompts the user for confirmation.
Features
- 🤖 AI-Powered: Uses OpenAI's GPT models to generate intelligent commit messages
- 🎯 Context-Aware: Analyzes actual code changes to create relevant messages
- ⚙️ Configurable: Supports TOML configuration and environment variables
- 🔄 Interactive: Prompts for confirmation with regenerate option
- 🔒 Safe: Never commits without explicit user confirmation
- 📦 Lightweight: Single binary with minimal dependencies
- 🎨 Gitmoji Support: Optional gitmoji integration for expressive commits
- 🔄 Multi-VCS: Supports both Git and Jujutsu (jj) version control systems
- ✅ Commitlint Integration: Validates commit messages with commitlint and auto-fixes violations
Installation
Prerequisites
- Go 1.19 or later
- Git installed and configured (or jj for Jujutsu support)
- OpenAI API key
- (Optional) Commitlint for commit message validation
Install Options
For now it is only possible to install from source or with the flake. Feel free to let me know if you want to see it somewhere else.
Build from source
git clone https://codeberg.org/ferrumboll/fast-commit
cd fast-commit
go build -o fast-commit
Build with flake
nix profile install git+https://codeberg.org/ferrumboll/fast-commit
# to update
nix profile upgrade fast-commit
Configuration
Configuration File
Create a configuration file at ~/.config/fast-commit.toml:
api_key = "your-openai-api-key-here"
model = "gpt-4"
base_url = "" # If you want to use OpenAI compatible APIs
extra_prompt = "Write concise, conventional commit messages following the format: type(scope): description"
use_gitmoji = true
use_full_gitmoji = true
vcs = "git" # or "jj" for Jujutsu
[commitlint]
enabled = false # Enable commitlint validation and auto-fixing
Environment Variables
You can also use environment variables as fallback:
export FAST_COMMIT_API_KEY="your-openai-api-key"
export FAST_COMMIT_MODEL="gpt-4"
export FAST_COMMIT_BASE_URL=""
export FAST_COMMIT_EXTRA_PROMPT="Write conventional commit messages"
export FAST_COMMIT_USE_GITMOJI="true"
export FAST_COMMIT_USE_FULL_GITMOJI="true"
export FAST_COMMIT_VCS="git" # or "jj"
export FAST_COMMIT_COMMITLINT_ENABLED="false"
Configuration Priority
- TOML configuration file
- Environment variables
- Default values (model: gpt-4, extra_prompt: empty, vcs: auto-detect)
Usage
Basic Usage
- Stage your changes (Git):
git add .
Or for Jujutsu (jj) there is no need to stage - jj tracks working copy changes automatically
- Run fast-commit:
fast-commit
- Review the generated commit message and choose:
yoryes: Commit with the generated messagenorno: Cancel the commitrorregenerate: Generate a new commit message
CLI Flags
| Flag | Description |
|---|---|
-y, --yes |
Skip confirmation prompt and commit immediately |
-c, --context <string> |
Provide additional context to the AI about why changes were made |
-p, --push |
Automatically push to remote after commit (Git: pushes current branch, jj: pushes most recent bookmark to @-) |
Example Workflows
Git Workflow
# Make some changes
echo "console.log('Hello World')" > hello.js
# Stage changes
git add hello.js
# Generate commit message with context
./fast-commit -c "Added basic logging for debugging purposes"
# Output:
# Generated commit message:
# ✨ feat: add hello world console log for debugging
#
# Do you want to commit with this message? [y/n/r]: y
# Changes committed successfully!
# (OR) Skip confirmation prompt
./fast-commit -y
Jujutsu (jj) Workflow
# Make some changes
echo "console.log('Hello World')" > hello.js
# Generate commit message (no staging needed)
./fast-commit -c "Added basic logging for debugging purposes"
# Output:
# Generated commit message:
# ✨ feat: add hello world console log for debugging
#
# Do you want to commit with this message? [y/n/r]: y
# Changes committed successfully!
# (OR) Skip confirmation prompt
./fast-commit -y
# (OR) Auto-push with fast bookmark detection
./fast-commit -p
# Automatically pushes the most recent bookmark from parent commits to @-
Commitlint Integration
Fast-commit includes built-in support for commitlint and commitlint-rs validation. When enabled, it automatically validates generated commit messages and uses AI to fix any violations.
How It Works
When commitlint integration is enabled:
- Validation: Each generated commit message is validated against your commitlint rules
- Auto-fixing: If validation fails, the AI automatically generates a corrected message
- Retry Logic: Up to 3 attempts are made to create a compliant message
- Transparency: All validation attempts and errors are shown to the user
- Gitmoji Handling: Emojis are automatically stripped before validation to avoid conflicts
User Interface
The interface shows detailed information about the validation process:
- Retry attempts: Orange-colored indicators showing each validation attempt
- Validation errors: Red-colored error messages from commitlint
- Final result: Green confirmation when a valid message is generated
Example output:
Generated commit message:
✨ feat: add user authentication system
Validation attempt 1: ❌ Failed
Error: subject may not be longer than 50 characters
Validation attempt 2: ✅ Passed
✨ feat: add user auth system
Do you want to commit with this message? [y/n/r]:
API Reference
Configuration
The configuration is loaded from ~/.config/fast-commit.toml with the following structure:
| Field | Type | Required | Description |
|---|---|---|---|
api_key |
string | Yes | OpenAI API key |
base_url |
string | No | OpenAI compatible api url |
model |
string | No | OpenAI model to use (default: gpt-4) |
extra_prompt |
string | No | Additional prompt instructions |
vcs |
string | No | VCS to use: "git", "jj", or empty for auto-detect (default: auto-detect) |
use_gitmoji |
bool | No | Enable gitmoji in commit messages (default: false) |
use_full_gitmoji |
bool | No | Use full gitmoji set instead of common set (default: false) |
commitlint.enabled |
bool | No | Enable commitlint validation and auto-fixing (default: false) |
Environment Variables
| Variable | Description |
|---|---|
FAST_COMMIT_API_KEY |
OpenAI API key |
FAST_COMMIT_BASE_URL |
OpenAI compatible api url |
FAST_COMMIT_MODEL |
OpenAI model to use |
FAST_COMMIT_EXTRA_PROMPT |
Additional prompt instructions |
FAST_COMMIT_VCS |
VCS to use: "git", "jj", or empty for auto-detect |
FAST_COMMIT_USE_GITMOJI |
Enable gitmoji in commit messages |
FAST_COMMIT_USE_FULL_GITMOJI |
Use full gitmoji set instead of common set |
FAST_COMMIT_COMMITLINT_ENABLED |
Enable commitlint validation and auto-fixing |
Development
Project Structure
fast-commit/
├── main.go # Entry point and CLI logic
├── config/ # Configuration handling
│ └── config.go
├── vcs/ # VCS abstraction layer
│ ├── interface.go # VCS interface
│ ├── git/ # Git implementation
│ │ └── git.go
│ └── jj/ # Jujutsu (jj) implementation
│ └── jj.go
├── openai/ # OpenAI API integration
│ └── client.go
├── prompt/ # User interaction
│ └── prompt.go
├── gitmoji/ # Gitmoji support
│ ├── gitmoji.go
│ ├── gitmojis.json
│ └── gitmojis_common.json
├── commitlint/ # Commitlint integration
│ └── commitlint.go
├── ui/ # User interface
│ └── ui.go
└── README.md # This file
Building
# Build for current platform
go build -o fast-commit
# Build for multiple platforms
GOOS=linux GOARCH=amd64 go build -o fast-commit-linux-amd64
GOOS=darwin GOARCH=amd64 go build -o fast-commit-darwin-amd64
GOOS=windows GOARCH=amd64 go build -o fast-commit-windows-amd64.exe
Testing
go test ./...
Contributing
- Fork the repository
- Create a feature/fix/refactor branch (
git checkout -b [feat|fix|refactor]/new-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
go test ./...) - Commit your changes
- Push to the branch
- Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.