- Published on
Bgit — Workflow Automation for Git
- Authors
- Name
- Sidharth Singh
- https://x.com/sid10singh
Bgit
Bgit is a lightweight, rule-driven Git workflow engine written in Rust, empowering teams to enforce pre-commit validations, hook-based automation, and configurable pipelines across repositories.
Inspired by real-world CI challenges, Bgit provides a local-first, pluggable CLI system that integrates deeply with Git internals using git2-rs
.
Features ⚙️
- ✅ Rule-Based Validation: Enforce structured rules like "no secrets staged", "Git name/email setup", or custom pre-push logic.
- 🧩 Atomic Events API: Modular Git operations (
add
,commit
,push
,init
, etc.) designed around theAtomicEvent
trait. - 🔌 Hook Integration: Auto-execute pre/post hooks in
.bgit/hooks
with support for shell scripts and language-based runners. - 🧠 Config-Driven Logic: Customize workflows, steps, and flags via a single
config.toml
in.bgit/
. - 📦 Extensible CLI: Built for maintainability and performance, powered by
git2
,serde
,toml
, andcolored
.
📐 Architecture Highlights
- 🧱 AtomicEvent Trait: All Git commands implement the
AtomicEvent
interface, supporting hooks, rules, and a unifiedexecute()
entry point. - 📜 Hook Runner Engine: Detects and runs appropriate
pre_*
andpost_*
hooks per event using file extension-based resolution. - 🧪 Rule Enforcement: Every atomic action is validated through a list of pluggable rules (defined via
Rule
trait), allowing enforcement levels likeError
,Warning
, etc. - ⚙️ TOML-based Config System: Centralized, human-readable configuration structure for workflows and rules.
- 🔄 Failsafe Defaults: Gracefully handles missing rules/hooks, ensuring non-disruptive fallback behavior in the absence of configurations.
Use Case Example 📘
Here’s how a git_add
operation looks with Bgit:
- Runs configured
pre_git_add
hook - Executes rules like:
NoSecretsStaged
IsGitInstalledLocally
- Adds files using
git2
APIs - Triggers
post_git_add
hook (if present)
You can configure this behavior with a simple .bgit/config.toml
:
[rules.default]
NoSecretsStaged = "Error"
IsGitInstalledLocally = "Warning"
[workflow.default.git_add]
skipAddAll = true
includeUntracked = false
🛠️ Tech Stack
- Rust 🦀 — for safety, performance, and concurrency.
- git2-rs 📘 — native Git bindings for low-level repo interaction.
- serde + toml 📦 — for powerful and flexible configuration parsing.
- colored + indicatif 🎨 — for a polished CLI user experience.
🚀 Getting Started
📦 Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
🔧 Install Bgit
cargo install bgit
🏁 Run
bgit
Follow the on-screen prompts to add, commit, and push your changes. bgit will handle the rest, ensuring that only relevant files are included and that your Git repository remains clean and organized.
🤝 Contributing
Bgit is still evolving — contributions around new rules, events, and hook runners are always welcome! Reach out via Issues or start a PR on the GitHub repository.