Git-like version control CLI backed by PostgreSQL with pg-xpatch delta compression
A Git-like version control CLI backed by PostgreSQL with pg-xpatch delta compression.
Your entire repo history is a queryable database.
-- Which files are always changed together?
SELECT a.path, b.path, COUNT(*) as times_together
FROM pgit_blobs a
JOIN pgit_blobs b ON a.commit_id = b.commit_id AND a.path < b.path
GROUP BY a.path, b.path
ORDER BY times_together DESC;
-- Who are the top contributors?
SELECT author_name, COUNT(*) as commits
FROM pgit_commits
GROUP BY author_name
ORDER BY commits DESC;
No scripts, no parsing git log output. Just SQL.
Benchmarked on tokio (4,375 commits, single branch, 178.6 MB uncompressed content):
| git | pgit | |
|---|---|---|
| Packfile / table data | 8.3 MB | 8.0 MB |
pgit uses only delta compression via pg-xpatch (no zlib). Storage efficiency is comparable to git's packfiles.
pgit search "pattern" searches all versions of all filesgo install github.com/imgajeed76/pgit/cmd/pgit@latest
Download pre-built binaries from Releases:
pgit_*_linux_amd64.tar.gz or pgit_*_linux_arm64.tar.gzpgit_*_darwin_amd64.tar.gz or pgit_*_darwin_arm64.tar.gzpgit_*_windows_amd64.zip# Debian/Ubuntu
sudo dpkg -i pgit_*_linux_amd64.deb
# RHEL/Fedora
sudo rpm -i pgit_*_linux_amd64.rpm
# Alpine
sudo apk add --allow-untrusted pgit_*_linux_amd64.apk
# Initialize a new repository
pgit init
pgit config user.name "Your Name"
pgit config user.email "you@example.com"
# Basic workflow
pgit add .
pgit commit -m "Initial commit"
pgit log
# Set up remote and sync
pgit remote add origin postgres://user:pass@host/database
pgit push origin
pgit stores everything in PostgreSQL, so you can query it directly:
# Built-in search across all history
pgit search "TODO" --path "*.rs"
pgit search --all "panic!" --ignore-case
# Raw SQL access
pgit sql "SELECT * FROM pgit_commits ORDER BY created_at DESC LIMIT 10"
-- Most frequently changed files
SELECT path, COUNT(*) as versions
FROM pgit_blobs
GROUP BY path
ORDER BY versions DESC
LIMIT 10;
-- File size growth over time
SELECT
EXTRACT(YEAR FROM c.created_at)::int as year,
pg_size_pretty(AVG(LENGTH(b.content))::bigint) as avg_size
FROM pgit_blobs b
JOIN pgit_commits c ON b.commit_id = c.id
GROUP BY EXTRACT(YEAR FROM c.created_at)
ORDER BY year;
To test push/pull/clone, you can spin up a pg-xpatch container as your remote:
# Start a pg-xpatch container (creates database 'myproject' automatically)
docker run -d --name pgit-remote \
-e POSTGRES_USER=pgit \
-e POSTGRES_PASSWORD=pgit \
-e POSTGRES_DB=myproject \
-p 5433:5432 \
ghcr.io/imgajeed76/pg-xpatch:latest
# Add it as a remote and push
pgit remote add origin postgres://pgit:pgit@localhost:5433/myproject
pgit push origin
The database name can be anything you want - just make sure it matches in both the container and the connection URL. pgit will initialize the schema automatically on first push.
pgit init
pgit import /path/to/git/repo --branch main
| Command | Description |
|---|---|
pgit init |
Initialize new repository |
pgit add <files> |
Stage files for commit |
pgit status |
Show working tree status |
pgit commit -m "msg" |
Create a commit |
pgit log |
Show commit history (interactive) |
pgit diff |
Show changes |
pgit show <commit> |
Show commit details |
pgit checkout <commit> |
Restore files |
pgit blame <file> |
Show line-by-line attribution |
pgit search <pattern> |
Search across history |
pgit sql <query> |
Run SQL queries on repository |
pgit remote add <name> <url> |
Add remote database |
pgit push <remote> |
Push to remote |
pgit pull <remote> |
Pull from remote |
pgit clone <url> [dir] |
Clone repository |
pgit import <git-repo> |
Import from Git |
pgit stats |
Show repository statistics |
pgit local start/stop |
Manage local container |
# Bash
pgit completion bash > /etc/bash_completion.d/pgit
# Zsh
pgit completion zsh > "${fpath[1]}/_pgit"
# Fish
pgit completion fish > ~/.config/fish/completions/pgit.fish
| Variable | Description |
|---|---|
PGIT_CONTAINER_RUNTIME |
Force docker or podman |
PGIT_ACCESSIBLE |
Set to 1 for accessibility mode (no animations) |
NO_COLOR |
Disable colored output |
MIT