Git Bundle: Offline Repository Transfer and Air-Gap Deployments

git bundle: move a repository without network access to the remote

Some servers cannot reach GitHub: a client’s production network that allows only SSH from the agency’s jump host, an air-gapped intranet, a customer who receives code by file transfer. A git bundle is a single file that contains commits, branches and tags like a remote repository. It can be cloned, fetched from and verified, and incremental bundles carry only the commits since the last one.

Problem: A plugin for a client’s internal WordPress must be delivered to a server without internet access. Today a ZIP of the working tree is copied over, so the server has no history, and nobody can tell exactly which commit is deployed.

Solution: Create a full bundle of the release branch once with git bundle create, clone from it on the server, deliver later releases as incremental bundles that start at the last delivered tag, check each with git bundle verify, and update the server with git fetch from the bundle file.

The first delivery

# on the developer machine
git bundle create ha-plugin-2.4.0.bundle main --tags
git bundle verify ha-plugin-2.4.0.bundle
sha256sum ha-plugin-2.4.0.bundle > ha-plugin-2.4.0.bundle.sha256
# on the server, after copying the files (scp via jump host, USB, file transfer)
sha256sum -c ha-plugin-2.4.0.bundle.sha256
git clone -b main ha-plugin-2.4.0.bundle /var/www/intranet/wp-content/plugins/ha-plugin
cd /var/www/intranet/wp-content/plugins/ha-plugin
git checkout v2.4.0

The bundle contains everything reachable from main and all tags. A clone from it is a normal repository with full history; the deployed state is a tag, and git describe or git log -1 tells exactly what runs. The checksum file detects a damaged transfer before git complains.

Incremental updates

# only the commits after the last delivered release
git bundle create ha-plugin-2.4.0..2.5.0.bundle v2.4.0..main --tags
git bundle verify ha-plugin-2.4.0..2.5.0.bundle
# on the server
git bundle verify /tmp/ha-plugin-2.4.0..2.5.0.bundle      # checks that the prerequisite commits exist here
git fetch /tmp/ha-plugin-2.4.0..2.5.0.bundle main:refs/remotes/bundle/main 'refs/tags/*:refs/tags/*'
git checkout v2.5.0

The range v2.4.0..main includes only new commits; such a bundle requires that the receiving repository already has v2.4.0. verify on the server says whether the prerequisites are present, so an out-of-order delivery is detected before anything changes. The fetch puts the bundle’s main into a separate ref, and the deploy switches to the new tag.

Bundle as a remote

git remote add delivery /mnt/transfer/ha-plugin-latest.bundle
git fetch delivery

If each delivery overwrites the same file path, the bundle can be configured as a remote and fetched like any other. That makes the update a one-liner in the deploy script on the server.

What a bundle does not contain

Only git objects and refs: no vendor/ folder if it is not committed, no built assets if they are ignored. For a WordPress plugin with Composer dependencies and a JavaScript build, deliver a release ZIP built in CI next to the bundle, or commit the built files on a release branch that is bundled. Signed tags travel inside the bundle, so the server can check them with git tag -v: git tags and signed releases.

NOTE: Bundles are also a simple offline backup of a repository, including all branches: git bundle create repo-backup.bundle --all. Unlike a copy of the .git folder, a bundle is one consistent file that can be verified. Deploying from git on a server in general: zero-downtime deployment with rsync and a symlink.