Every developer working with Docker, local PostgreSQL, MySQL, or SQLite has suffered this loop:
1. You work on `feature/checkout-v2`.
└── Ran migrations: added table `stripe_orders`, added column `users.billing_tier NOT NULL`.
2. Urgent production bug alert! You run:
└── `git checkout main`
3. You start the app or run tests on `main`.
4. 💥 CRASH:
└── ActiveRecord::PendingMigrationError / PrismaClientKnownRequestError:
"column users.billing_tier does not exist" or "schema mismatch detected".
- The Nuclear Option:
docker compose down -v && docker compose up -d
(Loses all your test seeds, logins, and mocked state. Takes minutes to re-seed). - The Manual Rollback Dance: Trying to rollback migrations on
feature/checkout-v2before switching, only to lose experimental test data. - The
.envNightmare: Manually maintainingDATABASE_URL_DEV,DATABASE_URL_CHECKOUT, and editing.envon every branch change. - Cloud Branching (Neon, PlanetScale): Great developer experience, but proprietary, paid, and requires an internet connection. It doesn't work for offline development or standard local Docker setups.
BranchBase brings instant, zero-copy database branching directly to your local machine and Docker containers.
+---------------------------+
| Developer Machine |
+---------------------------+
|
`git checkout branch-b`
|
v
[ BranchBase Git Hook ]
|
+--------------------+--------------------+
| |
(Detects new branch) (Zero-Copy Snapshot)
| |
v v
+---------------------------------------+ +------------------------------------+
| BranchBase Proxy (Port 5432) | | Local Database (PostgreSQL) |
+---------------------------------------+ +------------------------------------+
| - App connection string NEVER changes | | - `db_project_main` (frozen) |
| - Automatically routes queries to the | | - `db_project_branch_b` (active) |
| active Git branch database! | | (Created instantly via TEMPLATE) |
+---------------------------------------+ +------------------------------------+
- ⚡ Instant Branching: Creates a fresh, isolated branch database in milliseconds using PostgreSQL
CREATE DATABASE ... TEMPLATEor filesystem copy-on-write (reflink/APFS/Btrfs for SQLite). - 🔌 Transparent Connection Proxy: Your app's
DATABASE_URL=postgres://user:pass@localhost:5432/myappnever changes. The local proxy automatically inspects which Git branch is active in your working directory and routes traffic to that branch's database. - 🎣 Automated Git Hook: Hooks into
post-checkoutandpost-merge. You simply use standardgit checkoutorgit switch. - 🧹 Automatic Cleanup (
prune): When you delete or merge a Git branch,branchbasesafely tears down the associated ephemeral database. - 📴 100% Local & Offline: No cloud telemetry, no subscription fees, no internet needed.
| Feature | BranchBase 🌿 | Neon | PlanetScale | lakeFS | Liquibase |
|---|---|---|---|---|---|
| 100% Local & Offline | ✅ Yes | ❌ Cloud | ❌ Cloud | ❌ S3/ObjStore | ✅ Yes |
| PostgreSQL Support | ✅ Yes (TEMPLATE) | ✅ Yes | ❌ Vitess | ❌ S3/Blobs | ✅ Yes |
| MySQL / MariaDB Support | ✅ Yes (Table Clone) | ❌ No | ✅ Yes | ❌ S3/Blobs | ✅ Yes |
| SQLite Support (APFS/CoW) | ✅ Yes | ❌ No | ❌ No | ❌ No | ✅ Yes |
| Git-Native Hook Automation | ✅ Yes (post-checkout) |
❌ Manual | ❌ Manual | ❌ CLI only | ❌ Manual |
| Transparent TCP Wire Proxy | ✅ Yes (Zero .env edits) |
❌ N/A | ❌ N/A | ❌ N/A | ❌ N/A |
| Interactive Terminal UI | ✅ Yes (branchbase tui) |
❌ Web only | ❌ Web only | ❌ Web only | ❌ No |
| Docker Compose Auto-Detection | ✅ Yes | ❌ No | ❌ No | ❌ No | ❌ No |
| Cost / Licensing | 💚 Free & MIT | 💳 Paid / Freemium | 💳 Paid / Freemium | 💚 Open Core | 💳 Paid / OSS |
brew install oscarbol09/branchbase/branchbasego install github.com/oscarbol09/branchbase/cmd/branchbase@latestDownload standalone cross-platform binaries directly from GitHub Releases for Linux, macOS (Intel & Apple Silicon), and Windows.
git clone https://github.com/oscarbol09/branchbase.git
cd branchbase
go build -o bin/branchbase ./cmd/branchbase
sudo mv bin/branchbase /usr/local/bin/cd my-awesome-project
branchbase initbranchbase proxy# Branch to a new feature:
git checkout -b feature/stripe-billing
# Run migrations freely:
npx prisma migrate dev # or rails db:migrate / alembic upgrade head
# Switch back to main whenever you want:
git checkout main
# Proxy immediately routes traffic back to your main database! No migration errors!# Human-readable summary
branchbase status
# Interactive Terminal Dashboard
branchbase tui
# Machine-readable JSON for prompt scripts, CI/CD, or status bars
branchbase status --jsonbranchbase/
├── cmd/
│ └── branchbase/
│ └── main.go # CLI entry point (subcommands & signal handling)
├── internal/
│ ├── compose/ # Docker Compose auto-detection & environment parser
│ ├── config/ # Configuration loader (.branchbase.json / .yaml)
│ ├── driver/ # Database engine interfaces & registry
│ │ ├── driver.go # Core Driver interface contract
│ │ ├── mysql/ # MySQL & MariaDB engine (table cloning & metadata)
│ │ ├── postgres/ # PostgreSQL engine (TEMPLATE cloning)
│ │ └── sqlite/ # SQLite engine (CoW / Reflink snapshots)
│ ├── tui/ # Interactive Terminal UI (ANSI dashboard)
│ ├── git/ # Git HEAD inspector and branch sanitization
│ │ ├── resolver.go # Non-subshell .git/HEAD resolution
│ │ └── resolver_test.go # Table-driven unit test suite
│ ├── hook/ # Automated Git hook manager (post-checkout/merge)
│ │ ├── hook.go # Non-intrusive hook installer
│ │ └── hook_test.go # Hook lifecycle test suite
│ └── proxy/ # Transparent TCP proxy & wire routing
│ ├── pgwire/ # PostgreSQL wire-protocol StartupMessage rewriter
│ │ ├── pgwire.go # Packet parser & database replacer
│ │ └── pgwire_test.go # Protocol unit test suite
│ └── proxy.go # Zero-overhead bidirectional TCP forwarder
├── .agents/ # Custom Agent skills & development workflows
├── .github/ # CI workflows, issue templates, dependabot
├── ARCHITECTURE.md # Detailed system design & sequence diagrams
├── CONTRIBUTING.md # Contributor guide & driver creation tutorial
├── SETUP.md # Local developer environment setup guide
├── SECURITY.md # Security policy & private vulnerability reporting
├── CODE_OF_CONDUCT.md # Contributor Covenant v2.1
├── CHANGELOG.md # Keep a Changelog version history
├── branchbase.example.yaml # Annotated configuration specification
└── go.mod # Go 1.22+ module definition
- Detection: When you run
git checkout <branch>, BranchBase's hook (.git/hooks/post-checkout) detects the branch transition in under 5ms by reading.git/HEAD. - Identifier Sanitization: Special characters like
/or-in branch names (e.g.feature/stripe-v2) are converted into safe database identifiers (feature_stripe_v2). - Copy-on-Write Snapshot:
- PostgreSQL: Disconnects lingering connections to the template and executes
CREATE DATABASE <target> TEMPLATE <source>;(instant CoW clone). - MySQL / MariaDB: Dynamically clones schemas and tables (
CREATE TABLE ... LIKE,INSERT INTO ... SELECT) with zero-downtime transactional consistency. - SQLite: Issues
PRAGMA wal_checkpoint(TRUNCATE);and performs a filesystem reflink/clone (clonefile()orFICLONE). - Docker Compose: Automatically inspects
docker-compose.ymlto configure database ports and credentials without manual input.
- PostgreSQL: Disconnects lingering connections to the template and executes
- Transparent Routing: When your backend app queries
localhost:5432, the BranchBase proxy intercepts the connection, resolves the active branch database, and forwards traffic seamlessly. - Lifecycle Pruning: Once a PR is merged into
main, runningbranchbase pruneremoves the ephemeral database, freeing disk space.
External engines are pluggable by design. Adding a new database driver requires just 1 package and 1 interface implementation:
// internal/driver/driver.go
type Driver interface {
Name() string
Ping(ctx context.Context) error
BranchExists(ctx context.Context, branchName string) (bool, error)
CreateBranch(ctx context.Context, sourceBranch, targetBranch string) error
DeleteBranch(ctx context.Context, branchName string) error
ListBranches(ctx context.Context) ([]BranchInfo, error)
Close() error
}- Create
internal/driver/<engine>/<engine>.go. - Implement the
Driverinterface. - Register your factory via
driver.Register("<engine>", factory)ininit(). - See our dedicated Driver Development Skill for full instructions.
- ◬ Prisma ORM Integration Guide: Zero-conflict database migrations with TypeScript & Node.js.
- 🐳 Docker Compose Setup Guide: Zero-config containerized database branching.
Thinking about contributing? We'd love to have you!
- New Contributors: Check our
good first issuelabel for onboarding tasks. - Contributor Guide: Read CONTRIBUTING.md for coding standards, Conventional Commits, and PR rules.
- Environment Setup: See SETUP.md for local Go and Docker development steps.
- Code of Conduct: All interactions are governed by our Code of Conduct.
Thank you to all the amazing developers who contribute to making BranchBase the best local-first database branching tool!
If you find BranchBase useful in your daily development or it saved you hours of debugging migration mismatches, please consider giving us a star! It helps more developers discover the project.
If BranchBase brings value to your team or organization, consider supporting ongoing maintenance:
To report a vulnerability privately, please see SECURITY.md or use GitHub Private Vulnerability Reporting.
Licensed under the MIT License.
