This Git bundle error occurs when you try to unbundle or fetch from a bundle file that references commits your repository doesn't have. The bundle contains incremental changes that depend on base commits missing from your repo. Fix it by ensuring prerequisite commits exist before unbundling.
The "Repository lacks these prerequisite commits" error occurs when Git attempts to apply a bundle file that was created with a commit range (e.g., `old..new`), but your local repository doesn't have the commits that the bundle depends on. Git bundles are a way to transfer repository data without network access, but incremental bundles require certain base commits to already exist in the target repository. When you create a bundle with a range like `git bundle create update.bundle main ^origin/main`, Git creates a "thin pack" that contains only the differences. These differences reference parent commits that must exist in the destination repository. If they don't, Git cannot reconstruct the full objects and reports this error. The error message typically includes the SHA-1 hashes of the missing prerequisite commits, helping you identify what's needed. This commonly happens when: - A bundle was created from a more recent state than the recipient's repository - The recipient cloned with `--depth` or `--single-branch` and lacks history - The bundle creator and recipient are out of sync about their shared history - An intermediate bundle in a series was skipped
First, use git bundle verify to check what commits are required:
# Verify the bundle against your repository
git bundle verify update.bundle
# If successful, you'll see:
# The bundle contains X refs
# The bundle requires these X ref(s)
# If it fails, you'll see error messages like:
# error: Repository lacks these prerequisite commits:
# error: a1b2c3d4e5f6... Commit message hereThe listed commits are what your repository needs before it can apply this bundle. Note down these SHA-1 hashes for the next steps.
Inspect the bundle to understand what it includes:
# List the branches/refs in the bundle
git bundle list-heads update.bundle
# Example output:
# a1b2c3d4e5f6 refs/heads/main
# b2c3d4e5f6g7 refs/heads/feature
# You can also unbundle to a temp location to inspect
git clone update.bundle temp-repo
cd temp-repo
git log --onelineThis helps you understand the scope of the bundle and whether you're using the right one.
If you have network access to a remote with the missing commits, fetch them:
# Fetch all history from origin
git fetch origin
# Or fetch specific commits if you know them
git fetch origin <commit-sha>
# For shallow clones, unshallow to get full history
git fetch --unshallow origin
# Then verify the bundle again
git bundle verify update.bundleOnce the prerequisite commits exist locally, the bundle can be applied.
If you can't fetch prerequisites from a remote, ask the bundle creator for a self-contained bundle:
# The creator should run:
# For a complete bundle of a branch
git bundle create complete.bundle HEAD main
# Or for the entire repository
git bundle create full-repo.bundle --all
# Verify the new bundle is self-contained
git bundle verify complete.bundle
# Should show: "The bundle records a complete history"A self-contained bundle has no prerequisites and can be cloned into an empty repository.
If starting fresh, clone directly from the bundle:
# Clone the bundle as if it were a remote
git clone update.bundle my-project
# Move into the cloned directory
cd my-project
# Set up the original remote
git remote set-url origin https://github.com/user/repo.git
# Or add it alongside the bundle remote
git remote add origin https://github.com/user/repo.git
# Fetch latest from actual remote
git fetch originCloning from a bundle treats it as the source of truth and doesn't require prerequisites.
When using incremental bundles, ensure you apply them in order:
# Verify each bundle before applying
git bundle verify bundle-001.bundle # Base bundle
git bundle verify bundle-002.bundle # First increment
git bundle verify bundle-003.bundle # Second increment
# Apply in sequence
git fetch bundle-001.bundle main:refs/remotes/bundle/main
git fetch bundle-002.bundle main:refs/remotes/bundle/main
git fetch bundle-003.bundle main:refs/remotes/bundle/main
# Merge or rebase as needed
git merge bundle/mainEach incremental bundle depends on the previous one's commits existing in your repository.
When creating bundles for distribution, be explicit about prerequisites:
# Check what commits the recipient has
# (get this from them or from a tag/known point)
KNOWN_COMMIT="abc1234"
# Create bundle from that point forward
git bundle create update.bundle $KNOWN_COMMIT..HEAD
# Verify what prerequisites are needed
git bundle verify update.bundle
# For maximum compatibility, create a complete bundle
git bundle create safe.bundle HEAD --allUsing a known synchronization point prevents prerequisite mismatches.
### Understanding Git Bundle Format
Git bundles are packfiles with additional header information. When you create a bundle with a revision range, Git creates a "thin pack":
# Bundles with ranges create thin packs
git bundle create thin.bundle main ^origin/main
# Thin packs store objects as deltas against prerequisites
# This makes them smaller but requires those base objects to existThe bundle format includes:
- A list of prerequisite commits (what must exist in target repo)
- A list of refs being bundled (branches/tags)
- A packfile containing the objects
### Dealing with Shallow Clones
Shallow clones are a common source of this error:
# Check if your clone is shallow
git rev-parse --is-shallow-repository
# Returns "true" if shallow
# See the shallow boundary
cat .git/shallow
# Unshallow the repository
git fetch --unshallow origin
# Or deepen gradually
git fetch --depth=100 originIf you can't unshallow, you may need to fetch specific commits:
# Fetch a specific commit shallowly
git fetch --depth=1 origin <prerequisite-sha>### Using Git Replace for Grafts
In complex situations, you can use replacement refs to work around missing history:
# If a commit references parent P that you don't have,
# you can graft it to appear parentless or have a different parent
git replace --graft <commit-sha> [new-parent-sha]
# This creates a replacement ref that Git uses transparently
# List replacements
git replace -l
# Remove a replacement
git replace -d <replaced-commit>This is an advanced technique that modifies how Git interprets the history locally.
### Bundle Size Optimization
Balance between bundle size and prerequisites:
| Bundle Type | Size | Prerequisites | Best For |
|------------|------|---------------|----------|
| Complete (HEAD --all) | Large | None | Initial transfer |
| Branch (HEAD main) | Medium | None | Branch backup |
| Incremental (old..new) | Small | Yes | Regular syncs |
### Scripting Bundle Verification
For automated workflows:
#!/bin/bash
BUNDLE="$1"
if git bundle verify "$BUNDLE" 2>/dev/null; then
echo "Bundle is valid, applying..."
git fetch "$BUNDLE" '+refs/heads/*:refs/remotes/bundle/*'
else
echo "Bundle has missing prerequisites:"
git bundle verify "$BUNDLE" 2>&1 | grep "^error:"
exit 1
fi### Network-Free Repository Synchronization
For air-gapped or offline environments:
# Initial sync: create complete bundle on source
git bundle create initial.bundle --all
# Transfer initial.bundle via USB/media
# On target: clone from bundle
git clone initial.bundle repo
cd repo
git remote rename origin bundle-origin
git remote add origin <real-remote-url>
# Subsequent syncs: create incremental bundles
# On source, after noting recipient's HEAD
git bundle create update.bundle recipient-head..HEAD
# On target
git fetch update.bundle main:bundle/main
git merge bundle/main### Verifying Bundle Integrity
Ensure bundles aren't corrupted:
# Verify bundle structure
git bundle verify repo.bundle
# Check SHA-1 integrity of objects
git fsck --full
# After applying, verify repository state
git fsck --no-danglingkex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git