What goes wrong#
A range bundle records the commits it assumes the receiver has. Git calls them prerequisites. In this fixture, topic is one commit on top of main, whose last two commits are c2 and c3:
git bundle create topic.bundle main~1..topic
git bundle verify topic.bundle
In a full clone of main, verify prints the ref the bundle contains and the commit it requires, and exits 0. In a clone made with --depth 1, and in an empty repository, it prints:
error: Repository lacks these prerequisite commits:
error: 087208efc4e3006538adc8f4f5d03e8fe84b9026
and exits 1. Cloning straight from that file fails for the same reason, with exit 128. The shallow clone is the case that surprises people: its user has the repository and the branch tip checked out, and still lacks the commit the bundle needs. Git 2.43 produced these results. The git bundle manual describes both forms.
Choose the range#
| Receiver has | Create | Cost |
|---|---|---|
| Nothing | git bundle create all.bundle --all | Every reachable object, so every branch and tag goes with it |
| Nothing, and needs one branch | git bundle create topic.bundle topic | That branch's whole history |
| A full clone that holds a commit you can name | git bundle create topic.bundle BASE..topic | Only the new commits |
| A shallow clone | One of the first two | A range needs history the clone may not hold |
Ask the receiver for git rev-parse origin/main and git rev-parse --is-shallow-repository before you build a range. Two lines of text are cheaper than a second file transfer.
Check --all before it leaves your organization. It carries branches nobody mentioned, and a file deleted in the latest commit is still in the history.
Write the handoff#
- The bundle's name and its
sha256sum. - The output of
git bundle list-heads topic.bundle. - The prerequisite commit, or "self-contained".
- The command to import it:
git fetch topic.bundle topic:topic.
The receiver runs git bundle verify, fetches, and compares git rev-parse topic with the head you listed. The two match only if they have the same commit, and a commit names its tree and its whole ancestry.
What a verified bundle does not show#
verify checks the format and the prerequisites. It says nothing about files Git does not track, about submodules, whose commits live in another repository, or about Git LFS, where the history holds only pointers. If the project uses either, hand those over separately and name them in the message.
Worked example#
This example is fictional. A contractor's network blocks the code host, so Ana sends fix.bundle, built as main..fix. Verification fails on a prerequisite. The contractor's copy turns out to be a source archive committed into a new repository, so its history shares no commit with Ana's. A bundle cannot help with a range there. Ana sends a self-contained bundle of fix, and the contractor clones from it and rebuilds their two local commits on top as patches.
When you send a few commits for someone to apply on their own base, patches with a recorded base are the smaller handoff. The handoff guide lists the other forms.