Skip to content

init

The init command sets up pgbranch for a PostgreSQL database in your project directory.

Terminal window
pgbranch init -d <database> [flags]
FlagShortDescriptionDefault
--database-dDatabase name (required)-
--host-HPostgreSQL hostlocalhost
--port-pPostgreSQL port5432
--user-UPostgreSQL userpostgres
--password-WPrompt for password-
Terminal window
pgbranch init -d myapp_dev
Terminal window
pgbranch init -d myapp_dev -H localhost -p 5432 -U postgres
Terminal window
pgbranch init -d myapp_dev -W

You’ll be prompted to enter the password securely.

When you run pgbranch init, it:

  1. Creates the .pgbranch directory in the current folder
  2. Generates configuration with your database connection details
  3. Creates an encryption key for securing remote credentials
  4. Tests the database connection to ensure it’s accessible
.pgbranch/
├── config.json # Database and remote configuration
├── branches/ # Branch metadata storage
└── key # Encryption key (add to .gitignore)

The generated config.json looks like:

{
"database": "myapp_dev",
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "",
"remotes": {},
"defaultRemote": ""
}

If pgbranch is already initialized in the directory, running init again will show an error:

Error: pgbranch already initialized in this directory

To reinitialize, first remove the .pgbranch directory:

Terminal window
rm -rf .pgbranch
pgbranch init -d myapp_dev

After initialization:

  1. Create your first branch
  2. Check status
  3. Set up git hooks