Mirror Mode (GitHub + Crab)
Mirror mode lets you keep GitHub (or GitLab) for code review and pull requests while Crab handles large-file storage. Code goes to GitHub, large files go to your cloud bucket — your team's workflow stays unchanged.
Data Flow
When collaborators pull from GitHub, the post-checkout hook hydrates pointer files from the Crab remote automatically.
Setup: Repository Owner
Prerequisites
- A GitHub/GitLab repo with an
originremote already configured - An S3/GCS/Azure bucket for Crab storage
- Cloud credentials configured (AWS CLI, gcloud, or az)
Initialize
cd my-project
crab init --mirror=origin crab://my-bucket/my-repoThis command:
- Validates that the
originremote exists - Adds a
crabremote pointing to your bucket - Installs
pre-push,post-checkout, andpost-mergehooks - Generates
.crab.tomlwith a[mirror]section - Auto-tracks large file patterns in
.gitattributes
Push the configuration
crab ship -m "enable crab for large files"Now .crab.toml is on GitHub. Collaborators will inherit the mirror setup.
Setup: Collaborator
After cloning from GitHub:
git clone git@github.com:team/project.git
cd project
crab initRunning crab init with no URL detects the [mirror] section in .crab.toml and automatically:
- Adds the
crabremote - Installs mirror hooks
- Hydrates files per
[hydrate]settings
If the collaborator previously ran crab install --global, even the crab init step may be unnecessary — the global filter driver handles it.
How Hooks Work
pre-push — Before pushing to GitHub
#!/bin/sh
# Crab mirror: push xorbs before refs go to origin
crab add . --skip-git-add 2>/dev/null
crab push --remote crab --quiet 2>/dev/nullEnsures large-file content reaches your bucket before pointer blobs reach GitHub. If the Crab push fails, the git push is aborted — preventing dangling pointers.
post-checkout — After switching branches or cloning
#!/bin/sh
# Crab mirror: hydrate pointer files after checkout
crab hydrate . --quiet 2>/dev/null || trueMaterializes pointer files so you see real content after branch switches. Non-fatal on failure.
post-merge — After pulling or merging
#!/bin/sh
# Crab mirror: hydrate after merge/pull
crab hydrate . --quiet 2>/dev/null || trueSame behavior as post-checkout, triggered by git pull and git merge.
Existing hooks preserved
Crab appends its lines to existing hooks — it never overwrites your custom hooks. Installation is idempotent.
Checking Status
crab statusWith mirror mode active, you'll see:
Mirror: origin ↔ crab (crab://my-bucket/my-repo) | healthy
Crab remote: reachable
Pending push: 0 filesConfiguration
The [mirror] section in .crab.toml:
[mirror]
origin_remote = "origin" # GitHub/GitLab remote name
crab_remote = "crab" # Crab storage remote nameWhen to Use Mirror Mode
Use mirror mode when:
- Your team uses GitHub/GitLab for code review and CI
- You have large files (models, datasets, assets) that bloat git
- You want PRs to show pointer diffs, not binary blobs
- You need deduplication and lazy checkout for large files
Use standard mode when:
- Crab is your only remote (no GitHub/GitLab)
- You don't need code review on a separate platform
- You want the simplest possible setup
Troubleshooting
Hooks not firing
Verify hooks are installed:
ls -la .git/hooks/pre-push
cat .git/hooks/pre-push | grep "Crab mirror"Re-run crab init to reinstall if missing.
Hydration fails after pull
Check credentials and remote connectivity:
crab doctor
git remote get-url crabPush rejected by GitHub (file too large)
This means the pre-push hook didn't fire. Check that:
- The hook file exists and is executable
crabis on your PATH- Run
crab initto reinstall hooks
Related
- Project Configuration —
.crab.tomlreference crab init— the--mirrorflagcrab ship— one-command commit + push