init
The init command sets up pgbranch for a PostgreSQL database in your project directory.
pgbranch init -d <database> [flags]| Flag | Short | Description | Default |
|---|---|---|---|
--database | -d | Database name (required) | - |
--host | -H | PostgreSQL host | localhost |
--port | -p | PostgreSQL port | 5432 |
--user | -U | PostgreSQL user | postgres |
--password | -W | Prompt for password | - |
Examples
Section titled “Examples”Basic Initialization
Section titled “Basic Initialization”pgbranch init -d myapp_devWith Connection Details
Section titled “With Connection Details”pgbranch init -d myapp_dev -H localhost -p 5432 -U postgresWith Password Prompt
Section titled “With Password Prompt”pgbranch init -d myapp_dev -WYou’ll be prompted to enter the password securely.
What It Does
Section titled “What It Does”When you run pgbranch init, it:
- Creates the
.pgbranchdirectory in the current folder - Generates configuration with your database connection details
- Creates an encryption key for securing remote credentials
- Tests the database connection to ensure it’s accessible
Directory Structure Created
Section titled “Directory Structure Created”.pgbranch/├── config.json # Database and remote configuration├── branches/ # Branch metadata storage└── key # Encryption key (add to .gitignore)Configuration File
Section titled “Configuration File”The generated config.json looks like:
{ "database": "myapp_dev", "host": "localhost", "port": 5432, "user": "postgres", "password": "", "remotes": {}, "defaultRemote": ""}Re-initialization
Section titled “Re-initialization”If pgbranch is already initialized in the directory, running init again will show an error:
Error: pgbranch already initialized in this directoryTo reinitialize, first remove the .pgbranch directory:
rm -rf .pgbranchpgbranch init -d myapp_devNext Steps
Section titled “Next Steps”After initialization: