How to fix error: Repository lacks these prerequisite commits in Git

GitINTERMEDIATEMEDIUMUpdated Dec 6, 2025ยท 226 views

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.

Quick fix

Fixes error: Repository lacks these prerequisite commits

# 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 here
  1. Verify the bundle and identify missing commits
  2. Check what the bundle contains
  3. Fetch missing prerequisites from a remote
  4. Request a complete bundle from the source
git โ€” error
# 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 here
error: Repository lacks these prerequisite commits

What this error means

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

Typical symptoms

  • git bundle verify reports 'Repository lacks these prerequisite commits'
  • git fetch from a bundle file fails with missing commits error
  • git pull from a bundle shows prerequisite commit SHA-1 hashes
  • Unable to apply incremental bundle updates
  • git clone from bundle works but subsequent bundle updates fail
  • CI/CD pipeline fails when applying cached bundle files
  • Offline repository sync breaks after divergent history

Common causes

  1. Bundle was created with a commit range but target repo lacks the base commits
  2. Repository was shallow cloned and lacks the referenced commit history
  3. Incremental bundles applied out of order or with gaps
  4. Bundle creator's local state diverged from shared baseline
  5. Repository was cloned with --single-branch limiting available history
  6. Target repository had its history rewritten or commits pruned
  7. Bundle references commits from a branch that was never fetched
  8. Delta objects in thin pack reference objects not present locally

How to fix "error: Repository lacks these prerequisite commits"

1Verify the bundle and identify missing commits

First, use git bundle verify to check what commits are required:

bash
# 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 here

The listed commits are what your repository needs before it can apply this bundle. Note down these SHA-1 hashes for the next steps.

2Check what the bundle contains

Inspect the bundle to understand what it includes:

bash
# 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 --oneline

This helps you understand the scope of the bundle and whether you're using the right one.

3Fetch missing prerequisites from a remote

If you have network access to a remote with the missing commits, fetch them:

bash
# 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.bundle

Once the prerequisite commits exist locally, the bundle can be applied.

4Request a complete bundle from the source

If you can't fetch prerequisites from a remote, ask the bundle creator for a self-contained bundle:

bash
# 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.

5Clone from the bundle instead of fetching

If starting fresh, clone directly from the bundle:

bash
# 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 origin

Cloning from a bundle treats it as the source of truth and doesn't require prerequisites.

6Apply bundles in correct sequence

When using incremental bundles, ensure you apply them in order:

bash
# 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/main

Each incremental bundle depends on the previous one's commits existing in your repository.

7Create bundles with explicit prerequisites

When creating bundles for distribution, be explicit about prerequisites:

bash
# 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 --all

Using a known synchronization point prevents prerequisite mismatches.

Advanced notes

### 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":

bash
# 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 exist

The 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:

bash
# 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 origin

If you can't unshallow, you may need to fetch specific commits:

bash
# 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:

bash
# 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:

bash
#!/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:

bash
# 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:

bash
# 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-dangling

Frequently asked questions

What does "error: Repository lacks these prerequisite commits" mean?
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. bundle main ^origin/main, Git creates a "thin pack" that contains only the differences.
How do I fix "error: Repository lacks these prerequisite commits"?
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.
What causes "error: Repository lacks these prerequisite commits"?
Bundle was created with a commit range but target repo lacks the base commits Repository was shallow cloned and lacks the referenced commit history Incremental bundles applied out of order or with gaps
Is the "error: Repository lacks these prerequisite commits" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading