Bundles: Moving Commits Without a Network Connection
Package a repository, or just new commits, into a single file with git bundle: creating full and incremental bundles, verifying them and their prerequisites, cloning and fetching from a bundle, using bundles for offline transfer and backups, and bundle URIs that speed up clones.
kvi5hnuCode Sprout team member6 min readOn this page
Sometimes two repositories can't talk to each other: a machine with no network, a secure environment that only accepts files, a remote site with a slow link, or an archive that should survive for years. A bundle is a single file containing commits, branches and tags, which Git can clone from and fetch from just like a remote. Unlike patches (article 45), a bundle carries real commits with their IDs, merges and history intact.
Creating and cloning a full bundle
git init -q trail-guide && cd trail-guide
for page in lake ridge forest; do git commit -q --allow-empty -m "Add $page page"; done
git tag -a v1.0 -m "Version 1.0"
git branch maps
git bundle create ../trail-guide.bundle --all
git bundle verify ../trail-guide.bundle
cd ..
git clone -q trail-guide.bundle copy
cd copy
git log --oneline
git branch -a
The bundle contains these 4 refs:
../trail-guide.bundle is okay
769bcbb15a52022cf0cd9375fbe7691cb360af9e refs/heads/main
769bcbb15a52022cf0cd9375fbe7691cb360af9e refs/heads/maps
1bc513357b6e68ce14df1e19bc1cd405dd4ccce5 refs/tags/v1.0
769bcbb15a52022cf0cd9375fbe7691cb360af9e HEAD
The bundle records a complete history.
The bundle uses this hash algorithm: sha1
769bcbb Add forest page
b75b0fc Add ridge page
d7b060a Add lake page
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
remotes/origin/maps
git bundle create <file> <refs>writes the named references and everything they need.--allincludes every branch and tag. Name branches to include only some:git bundle create site.bundle main maps.git bundle verifychecks the file is valid and complete for the current repository, and lists its references.git bundle list-heads <file>lists only the references.git clone <file>works like cloning from a server: the bundle becomesorigin, and its branches become remote-tracking branches. Afterwards, pointoriginat the real server withgit remote set-urlwhen there is one.
Incremental bundles
Sending the whole repository each time wastes space. An incremental bundle contains only the commits the other side doesn't have yet, given as a range:
git init -q trail-guide && cd trail-guide
for page in lake ridge; do git commit -q --allow-empty -m "Add $page page"; done
git tag -a sent-1 -m "Last commit sent to the field office"
git bundle create ../full.bundle --all 2>/dev/null
cd ..; git clone -q full.bundle field-office; cd trail-guide
git commit -q --allow-empty -m "Add forest page"
git commit -q --allow-empty -m "Add cave page"
git bundle create ../update.bundle sent-1..main
git bundle verify ../update.bundle 2>&1 | grep -v "^The bundle uses"
cd ../field-office
git fetch ../update.bundle main:refs/remotes/origin/main
git log --oneline origin/main
echo "=== in a repository without the prerequisite commit"
cd ..; git init -q empty; cd empty
git bundle verify ../update.bundle 2>&1 | tail -2
The bundle contains this ref:
../update.bundle is okay
3fa27510f293d62e5494992269afa1eaf33348b3 refs/heads/main
The bundle requires this ref:
b75b0fc6e0fadaf2f91733921d5222c1eee65c8e
From ../update.bundle
b75b0fc..3fa2751 main -> origin/main
3fa2751 Add cave page
769bcbb Add forest page
b75b0fc Add ridge page
d7b060a Add lake page
=== in a repository without the prerequisite commit
error: Repository lacks these prerequisite commits:
error: b75b0fc6e0fadaf2f91733921d5222c1eee65c8e
sent-1..mainbundles the commits reachable frommainbut not fromsent-1. The receiving repository must already havesent-1's commit: that's the bundle's prerequisite, whichverifyreports.- On the receiving side,
git fetch <bundle> <ref>:<local-ref>brings the commits in. Here they go toorigin/main, then a normalgit mergeorgit pullfrom that branch updates the localmain. - Without the prerequisite, verification fails with "Repository lacks these prerequisite commits", and so would a fetch.
- Time-based ranges work too:
git bundle create week.bundle --since=7.days main. Tags marking what was sent, likesent-1, make the next range easy. Move or add one after each transfer.
Practical uses
- Air-gapped transfer: carry a bundle on a USB drive to a machine with no network. Bundles move all history and branches in one file, and
verifycatches a corrupted or incomplete copy. - Backups:
git bundle create backup-2026-11.bundle --allproduces one file that's easy to store and checksum. Restore withgit clone. Uncommitted work, older stashes and configuration aren't included:--allcarriesrefs/stash, which is only the most recent stash. - Sending work to someone who can't reach your server, with history intact, which patches can't do for merges.
- Archiving a project's full history in a self-contained form.
git bundle create reads only committed data. Use --all for completeness. Include tags explicitly, or with --all, since a bundle of main alone doesn't carry tags.
Bundle URIs: faster clones
Servers can offer a bundle URI: a pre-built bundle, usually on a content delivery network, that clients download first, fetching only the remaining new objects from the Git server afterwards. That makes initial clones of big repositories faster and cheaper for the server.
git clone --bundle-uri=https://cdn.example.com/trail-guide.bundle https://git.example.com/trail-guide.git
Servers can also advertise bundle URIs themselves, in which case clients configured with transfer.bundleURI=true use them automatically. Since Git 2.50, clones use all references recorded in such bundles, not only branches, to reduce what's fetched afterwards.
What's current
- Since Git 2.48, cloning or unbundling from a bundle can check the new objects with fsck, at configurable strictness, so a bundle from an untrusted source can be checked as it's read.
- Bundle URIs speed up clones of large repositories, and Git 2.50 improved how they're used.
- Git 2.48's documentation stresses using
--allwhen making backup bundles, so that no branches or tags are missed.
Common questions
What's the difference between a bundle and a patch?
A patch describes changes as text, and git am creates new commits from it. A bundle contains the actual commit objects, with the same IDs, including merges, branches and tags.
Can I push to a bundle?
No. Bundles are read-only files: create a new one with git bundle create to send more commits.
Does a bundle include my uncommitted changes or stashes?
Uncommitted changes, no: only the references you name, and the commits and files they reach. Stashes partly: --all includes refs/stash, which is the most recent stash. Older entries, stash@{1} and so on, live in the stash's reflog, which bundles don't carry, so commit or export them first (git stash export, article 27).
How large is a bundle? About the size of a packed repository for the same commits, because a bundle is a header followed by a packfile (article 50). Incremental bundles are as small as the new commits.
Summary
git bundle create <file> --all, or with specific branches, puts commits, branches and tags into one file.git bundle verifychecks a bundle and its prerequisites, andlist-headslists its references.git clone <bundle>andgit fetch <bundle> <ref>:<local-ref>treat the file like a remote.- Incremental bundles (
<sent>..main) need the receiver to have the prerequisite commits. Tags marking what was sent make ranges easy. - Bundles suit offline transfer, backups and archives. Bundle URIs speed up large clones.
Practice questions
You need to give the complete history of a repository, with all branches and tags, to someone on a machine without network access. What do you do?
Answer
git bundle create project.bundle --all
git bundle verify project.bundle
Copy the file over. On the other machine: git clone project.bundle project. The bundle becomes origin, so they can later run git remote set-url origin <server-url> if a server becomes reachable.
Last week you sent a full bundle and tagged the sent commit as sent-1. How do you send only this week's commits on main?
Answer
git bundle create update.bundle sent-1..main, then move the marker for next time with git tag -f -a sent-1 -m "..." main (or create sent-2). The receiver runs git bundle verify update.bundle and git fetch update.bundle main:refs/remotes/origin/main, then merges.
git bundle verify reports "Repository lacks these prerequisite commits". What does it mean?
Answer
The bundle is incremental: it was created from a range, and the commit at the start of that range must already be in the receiving repository. This repository doesn't have it, perhaps because an earlier bundle wasn't applied. Apply the missing earlier bundle first, or ask for a full bundle made with --all.
Previous: Patches: diff, format-patch, am, apply and send-email
Next: Rewriting History: Authors, Dates, Secrets and Big Files With filter-repo

More in Git Course
Quiz: Git Delicate Details
Twenty-five questions on Git's subtle corners: what commit -a and stash leave out, empty folders, ignore patterns and negation, HEAD~ versus HEAD^, ours and theirs in a rebase, tags that don't move or don't push, describe, merge reverts, diff exit codes, stash conflicts and more.
Quiz: Git Interview Questions
Thirty Git questions of the kind asked in developer interviews: Git versus GitHub, the staging area, merge versus rebase, fetch versus pull, reset, revert and restore, detached HEAD, conflicts, force pushing, stash, cherry-pick, reflog, bisect, submodules, LFS and how commits are identified.
Quiz: Git Course Final Exam (All Parts)
The final exam for the Git course: thirty questions across all twelve parts, from the three areas and staging through branching, remotes, undoing, history investigation, configuration, tags, larger projects, patches, rewriting, internals and troubleshooting.
Quiz: Professional Git Practice (Git Part 12)
Sixteen questions on migrating to Git from Subversion, TFVC and Mercurial, team best practices for commits, branches and reviews, repository hygiene, and diagnosing and fixing the most common Git errors, with explanations.
Discussion
Sign in to ask a question or share what you learned.