← All apps

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.

View on GitHub → Set it up ↓

  • Latest Release
  • Release Workflow
  • Go 1.22+
  • PostgreSQL
  • macOS | Linux | Windows
  • Zero Dependencies
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.

  1. Install the tool

    Download the latest build for your system from the Releases page of the GitHub repo, unpack it, and put pgtwig in a folder on your PATH, such as ~/.local/bin. Or build it from source: run this inside the pgtwig folder.

    go build -o ~/.local/bin/pgtwig ./cmd/pgtwig
  2. Turn it on in your project

    Use the database name your app already uses. This adds a post-checkout hook.

    pgtwig init --db myapp_dev
  3. 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
  4. Go back

    pgtwig saves feature/billing and brings the other database back at once.

    git checkout main

Read the full README on GitHub

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