bragit

Crates.iobragit
lib.rsbragit
version0.1.0
created_at2025-10-31 16:15:43.36108+00
updated_at2025-10-31 16:15:43.36108+00
descriptionCommit specific files directly to target branches without switching.
homepagehttps://github.com/mya-ai/bragit
repositoryhttps://github.com/mya-ai/bragit
max_upload_size
id1910272
size38,740
Andy Bell (andyjsbell)

documentation

README

bragit 🪄

bragit is a Rust CLI tool that lets you commit specific files directly to target branches without switching branches.

This tool is built on top of libragit2 via the git2 crate, providing a fast and native way to automate cross-branch commits in Git repositories.


✨ Features

  • 🔀 Commit to any branch without checkout
  • 🧭 Auto-discovers your current repository
  • 🪶 Works from your normal working tree (no detached HEADs)
  • 🌱 Can start a new branch from origin/<branch> with --track-remote
  • 🚀 Optional --push support (delegates to git push for normal authentication)
  • 🔒 Safe: commits are atomic and branch-local

🧩 Installation

Install directly from crates.io:

cargo install bragit

Or build from source:

git clone https://github.com/mya-ai/bragit.git
cd bragit
cargo build --release
cp target/release/bragit ~/.local/bin/

🧠 Usage

Commit a file directly to a branch

bragit commit --branch feature/ui src/ui.rs

With a custom message

bragit commit --branch hotfix/login src/login.rs -m "Fix login redirect"

Push immediately after committing

bragit commit --branch release/1.2.3 dist/app.js --push

Track a remote branch if missing

If the branch doesn’t exist locally, use --track-remote to seed it from origin/BRANCH:

bragit commit --branch feature/experimental new/feature.rs --track-remote

⚙️ Command Reference

bragit commit \
  --branch <BRANCH> \
  [--message <MSG>] \
  [--push] \
  [--track-remote] \
  [--repo <PATH>] \
  <FILE>

Flags

Flag Description
--branch Target branch to commit to
--message, -m Custom commit message (default: Update <file>)
--push Push the branch to origin after committing
--track-remote Create local branch from remote if missing
--repo Optional path to Git repo (auto-detects by default)

🧱 How It Works

  1. Opens or discovers the Git repository.
  2. Finds the target branch (creates it from remote if needed).
  3. Hashes the provided file into a blob.
  4. Rebuilds the target branch tree with that file.
  5. Creates a new commit object pointing to that tree.
  6. Optionally calls git push to sync the branch to origin.

All without switching branches or touching your working index.


⚠️ Notes & Limitations

  • Does not run Git hooks (like pre-commit) — since it bypasses normal checkout.
  • Does not merge; it only commits changes directly to the branch head.
  • Assumes your repository is non-bare and accessible.
  • To avoid overwriting concurrent changes, you should rebase or pull the target branch before running this tool.

🧪 Example Workflow

# Commit fileA to branchA
bragit commit --branch branchA fileA.txt -m "Update A"

# Commit fileB to branchB
bragit commit --branch branchB fileB.txt -m "Update B"

# Push both
bragit commit --branch branchA fileA.txt --push
bragit commit --branch branchB fileB.txt --push

🔮 Roadmap

  • Multi-file commits per branch
  • Bulk mode: bragit commit --map "a.txt:branchA" "b.txt:branchB"
  • Hook-aware mode using temporary worktrees
  • Dry-run / diff preview mode

🪪 License

MIT © 2025 Andy Bell


🤝 Contributing

Pull requests are welcome! If you’d like to add features or improve UX, fork the repo and submit a PR.

git clone https://github.com/mya-ai/bragit.git
cd bragit
cargo run -- commit --branch test examples/demo.txt
Commit count: 0

cargo fmt