pgtwig
pgtwig is a small command line tool. Your app keeps the same database name and DATABASE_URL. When you run git checkout, pgtwig saves the database of the branch you leave and brings back the one for the branch you enter. A branch you have visited before switches back at once. A new branch gets a copy.
- Free · Open source
- MIT licence, on GitHub
- macOS, Linux, Windows
- amd64 and arm64
- Local or Docker
- PostgreSQL 12+
- Never blocks
- git checkout, even if Postgres is off
Set it up · 4 steps
You can try pgtwig on one project in a few minutes. Here is the short way.
What you need
- Git and a Git project to run it in.
- PostgreSQL 12 or newer installed locally or running in Docker.
- psql installed locally or inside your Postgres Docker container.
- Go 1.22 or newer to build it from source.
Postgres in Docker? Add --container my-postgres to the init command. On Windows, build with the PowerShell command in the README.
-
Install the tool
Download the latest build for your system from the Releases page of the GitHub repo, unpack it, and put
pgtwigin a folder on yourPATH, such as~/.local/bin. Or build it from source: run this inside the pgtwig folder.go build -o ~/.local/bin/pgtwig ./cmd/pgtwig -
Turn it on in your project
Use the database name your app already uses. This adds a
post-checkouthook.pgtwig init --db myapp_dev -
Make a branch
pgtwig saves the database of the branch you leave and makes a fresh copy for the new one.
git checkout -b feature/billing -
Go back
pgtwig saves
feature/billingand brings the other database back at once.git checkout main
Why it exists
I got tired of fixing broken migrations and losing my local test data every time I switched branches. You can try a migration or break your test data on one branch, and switch back to find the other branch’s data as you left it. pgtwig never blocks git checkout, even if Postgres or Docker is off.
GoPostgreSQLGit hooks