Background & Why Use git bundle?
Many financial projects, industrial plants, or government systems run on air-gapped networks—completely isolated from the Internet. That brings up a familiar challenge: how do you transfer code from a developer machine into an internal system while preserving full commit history and branches?
Many junior developers simply compress the entire project folder into a .zip or .tar.gz archive and copy it over via USB. This manual approach usually causes three major headaches:
- Bloated file sizes: A source code repository might only be around 15 MB, but once
node_modules,vendor, or build artifacts get included, the archive can easily balloon to 1–2 GB. - Corrupted Git structure: Copying the raw
.gitfolder over a USB drive (especially FAT32/exFAT) or between Linux and Windows can easily break file execute permissions (chmod +x), snap symlinks, and corrupt the index. - Painful re-syncing: Changing just 50 KB of code still forces you to re-archive and copy the entire 2 GB bundle all over again.
Not to mention times when you need a quick backup before performing a risky operation. I once lost important code just from accidentally force-pushing to the wrong branch. Since that slip-up, I’ve always been careful with git push --force and made it a habit to create a clean snapshot before touching commit history.
Git has a built-in command that cleanly solves both problems: git bundle. It packages all or part of a repository into a single binary file, typically with a .bundle extension. This file acts just like a real remote repository. You can git clone, git fetch, or git pull directly from it without a network connection or an intermediate Git server.
Preparing the Environment
You don’t need to install any third-party tools. The git bundle feature has been built into standard Git since version 1.5.0 (released in 2007).
First, verify that both the source machine and the destination (air-gapped) machine have Git installed:
git --version
If the machine inside the isolated network doesn’t have Git yet, you’ll need to download an offline installer (.deb, .rpm on Linux, or .exe on Windows) from an external machine and bring it in to install. On the source machine, make sure to check two more things:
- Run
git statusto ensure all necessary changes have been committed. Thegit bundlecommand only packages commit history, ignoring uncommitted changes and untracked files. - Prepare a USB drive, portable hard drive, or internal file transfer channel approved by your security team.
How to Package and Restore with git bundle
Depending on whether you’re transferring code for the first time or syncing regular updates, you’ll use one of the two methods below.
1. Packaging the Entire Repository (Full Bundle)
When moving a project to an air-gapped machine for the first time, cd into the repository’s root directory and package all branches and tags:
git bundle create project-full.bundle --all
If you want a smaller file and want to avoid exposing experimental branches, just package the main branch along with HEAD:
git bundle create project-main.bundle HEAD main
(Including HEAD allows git clone on the destination machine to automatically check out the main branch without throwing a missing HEAD error.)
2. Restoring Code from a Bundle File on the Destination Machine
After copying project-full.bundle to the offline machine, clone directly from that file just as you would from GitHub:
git clone project-full.bundle my-project
cd my-project
git log --oneline -n 5
Checking with git remote -v, you’ll see that origin points directly to the .bundle file path. Commit history, author names, and timestamps are all preserved intact. One quick note: you can only fetch or pull from a bundle file—you cannot git push back into it.
3. Creating Incremental Bundles for Daily Updates
For a repository around 1.2 GB in size, running --all every day wastes both disk space and copy time. Instead, you should only package the new commits created since the last sync. For instance, 20 bug-fix commits in a day typically produce a bundle file of only about 200–400 KB.
The easiest way to manage this is to place a milestone tag on the source machine. Right after creating the first full bundle on the main branch, create a marker tag:
git tag sync-point main
A few days later, once main has new commits, package only the delta since sync-point:
git bundle create update-02.bundle sync-point..main
Once done, remember to move the marker tag forward to the new position for the next sync:
git tag -f sync-point main
On the air-gapped machine, navigate into the my-project directory and pull directly from the update file:
git pull /duong-dan/toi/update-02.bundle main
If you want to carefully inspect the code changes before merging, fetch into a temporary branch and run diff:
git fetch /duong-dan/toi/update-02.bundle main:review-branch
git diff main..review-branch
Verifying & Validating the Bundle File Before Transfer
Discovering that you brought a corrupted file into an air-gapped lab means having to go all the way back to the source machine. So don’t skip the integrity check.
1. Validating Structure with git bundle verify
Before unplugging the USB drive and right after copying the file to the destination machine, run Git’s built-in verification command:
git bundle verify project-full.bundle
A valid file returns two confirmation lines: The bundle records a complete history and project-full.bundle is okay.
For incremental update files specifically, you need to run git bundle verify /duong-dan/toi/update-02.bundle from inside the repository on the destination machine. Git will check whether the destination machine already has the prerequisite commits. If any intermediate update is missing, it immediately reports an error along with the missing commit hash.
2. Quickly Inspecting Branches and Tags Inside a Bundle
Worried you packaged the wrong branch or forgot a release tag? You can preview the list of references without extracting anything:
git bundle list-heads project-full.bundle
This command prints every commit hash along with the branch and tag names (refs/heads/..., refs/tags/...) stored in the file.
3. Verifying File Integrity with a Checksum
Aging USB drives can develop bad sectors that corrupt binary data. To make sure the file wasn’t damaged in transit, generate a SHA-256 hash on the source machine:
sha256sum project-full.bundle > project-full.bundle.sha256
Once copied to the destination machine, run the verification command before performing any Git operations:
sha256sum -c project-full.bundle.sha256
Seeing OK means the file is 100% intact. When working with a large team, it’s good practice to log the creation date, bundle filename, marker tag, and SHA-256 hash in a small transfer.log file. That way, whenever you need to reconcile versions between the two environments, you can look it up right away.

