Configuration
pgbranch stores its configuration in .pgbranch/config.json within your project directory.
File Location
Section titled “File Location”your-project/├── .pgbranch/│ ├── config.json # Main configuration│ ├── branches/ # Branch metadata│ │ ├── main.json│ │ └── feature.json│ └── key # Local encryption key (deprecated)├── src/└── ...Configuration Schema
Section titled “Configuration Schema”{ "database": "string", "host": "string", "port": "number", "user": "string", "password": "string", "remotes": { "<name>": { "name": "string", "type": "string", "url": "string", "options": {} } }, "defaultRemote": "string"}Fields
Section titled “Fields”Database Connection
Section titled “Database Connection”| Field | Type | Required | Default | Description |
|---|---|---|---|---|
database | string | Yes | - | PostgreSQL database name |
host | string | No | localhost | PostgreSQL host |
port | number | No | 5432 | PostgreSQL port |
user | string | No | postgres | PostgreSQL user |
password | string | No | "" | PostgreSQL password |
Remotes
Section titled “Remotes”| Field | Type | Required | Description |
|---|---|---|---|
remotes | object | No | Map of remote configurations |
defaultRemote | string | No | Name of default remote |
Remote Configuration
Section titled “Remote Configuration”Each remote in the remotes object:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Remote identifier |
type | string | Yes | Backend type (s3, filesystem, r2) |
url | string | Yes | Remote URL |
options | object | No | Backend-specific options |
Example Configurations
Section titled “Example Configurations”Minimal (Local Only)
Section titled “Minimal (Local Only)”{ "database": "myapp_dev", "host": "localhost", "port": 5432, "user": "postgres"}With S3 Remote
Section titled “With S3 Remote”{ "database": "myapp_dev", "host": "localhost", "port": 5432, "user": "postgres", "remotes": { "origin": { "name": "origin", "type": "s3", "url": "s3://my-bucket/pgbranch", "options": { "region": "us-east-1", "accessKeyId": "ENC:v1:...", "secretAccessKey": "ENC:v1:..." } } }, "defaultRemote": "origin"}With Multiple Remotes
Section titled “With Multiple Remotes”{ "database": "myapp_dev", "host": "localhost", "port": 5432, "user": "postgres", "remotes": { "team": { "name": "team", "type": "s3", "url": "s3://team-bucket/pgbranch", "options": { "region": "us-east-1", "accessKeyId": "ENC:v1:...", "secretAccessKey": "ENC:v1:..." } }, "backup": { "name": "backup", "type": "filesystem", "url": "/mnt/backup/pgbranch" }, "r2": { "name": "r2", "type": "r2", "url": "r2://account123/pgbranch-bucket/snapshots", "options": { "accessKeyId": "ENC:v1:...", "secretAccessKey": "ENC:v1:..." } } }, "defaultRemote": "team"}With MinIO
Section titled “With MinIO”{ "database": "myapp_dev", "host": "localhost", "port": 5432, "user": "postgres", "remotes": { "minio": { "name": "minio", "type": "s3", "url": "s3://pgbranch-bucket/snapshots", "options": { "endpoint": "http://minio.local:9000", "accessKeyId": "ENC:v1:...", "secretAccessKey": "ENC:v1:...", "forcePathStyle": true } } }, "defaultRemote": "minio"}Remote Options by Type
Section titled “Remote Options by Type”S3 Options
Section titled “S3 Options”| Option | Type | Required | Description |
|---|---|---|---|
region | string | Yes* | AWS region |
accessKeyId | string | Yes* | AWS access key (encrypted) |
secretAccessKey | string | Yes* | AWS secret key (encrypted) |
endpoint | string | No | Custom S3 endpoint (for MinIO) |
forcePathStyle | boolean | No | Use path-style URLs |
*Can be provided via environment variables instead
R2 Options
Section titled “R2 Options”| Option | Type | Required | Description |
|---|---|---|---|
accessKeyId | string | Yes | R2 access key (encrypted) |
secretAccessKey | string | Yes | R2 secret key (encrypted) |
Filesystem Options
Section titled “Filesystem Options”No options required for filesystem remotes.
Branch Metadata
Section titled “Branch Metadata”Branch files in .pgbranch/branches/:
{ "name": "feature-auth", "created": "2024-01-15T14:22:00Z", "parent": "main", "snapshot": "pgbranch_feature_auth_abc123", "lastAccessed": "2024-01-16T10:30:00Z"}Environment Variables
Section titled “Environment Variables”pgbranch respects standard PostgreSQL and AWS environment variables:
PostgreSQL
Section titled “PostgreSQL”| Variable | Description |
|---|---|
PGHOST | PostgreSQL host |
PGPORT | PostgreSQL port |
PGUSER | PostgreSQL user |
PGPASSWORD | PostgreSQL password |
PGDATABASE | PostgreSQL database |
AWS/S3
Section titled “AWS/S3”| Variable | Description |
|---|---|
AWS_ACCESS_KEY_ID | AWS access key |
AWS_SECRET_ACCESS_KEY | AWS secret key |
AWS_REGION | AWS region |
AWS_ENDPOINT_URL | Custom S3 endpoint |
Environment variables take precedence over config file values.
Version Control
Section titled “Version Control”Safe to Commit
Section titled “Safe to Commit”.pgbranch/config.json(if using encrypted credentials or no passwords).pgbranch/branches/*.json
Do Not Commit
Section titled “Do Not Commit”.pgbranch/config.jsonif it contains plaintext database passwords~/.pgbranch_key(user-level encryption key)
Recommended .gitignore
Section titled “Recommended .gitignore”# Only if config contains plaintext passwordsEditing Configuration
Section titled “Editing Configuration”While you can edit config.json manually, it’s recommended to use commands:
# Database settingspgbranch init -d newdb -H newhost
# Remotespgbranch remote add name urlpgbranch remote remove namepgbranch remote set-default nameValidating Configuration
Section titled “Validating Configuration”pgbranch validates config on every command. Common validation errors:
Error: database name is requiredError: invalid remote URL formatError: remote 'origin' not foundMigrating Configuration
Section titled “Migrating Configuration”If you need to update configuration format:
# Backup current configcp .pgbranch/config.json .pgbranch/config.json.bak
# Reinitialize (preserves branches)pgbranch init -d myapp_dev
# Re-add remotespgbranch remote add origin s3://bucket/prefix