Git and GitHub / Advanced: trust, scale, and recovery / Lesson 21
Git bundles and restore verification
Create and inspect a portable Git bundle in a disposable lab, then verify a restore and its important limits.
On this page
Lesson goals
- Create a bundle of selected references.
- Verify and clone a self-contained bundle.
- Distinguish Git objects from uncommitted and external data.
Define the transfer contract
A Git bundle packages selected references and objects for offline transfer or backup. A self-contained bundle can be cloned without another repository, while an incremental bundle can require prerequisite objects at the recipient. Decide which references and data the recipient needs and how the file is protected. A bundle is not automatically a complete backup of the working machine or hosted collaboration service.
Create and verify in a lab
In a disposable repository with at least one synthetic commit, these commands create a bundle from all refs and inspect it. The output path is relative to the lab repository and must not overwrite an existing file. Verification checks bundle validity and prerequisites in its current repository context; it does not prove that the file includes every desired branch, uncommitted file or external asset.
git bundle create ../workshop.bundle --all
git bundle verify ../workshop.bundle
Verification reports the bundled references and any prerequisites.
The bundle captures objects reachable from selected refs; verify inspects its integrity and prerequisites.
Test a fresh restore
From the same lab repository, clone the self-contained bundle into a new sibling directory and inspect its history. Ensure that the destination does not already exist and compare the restored refs and content with the intended source. Do not run this in the shared workspace. A clone can succeed while still missing data that was never included in the bundle.
git clone ../workshop.bundle ../restore-lab
git -C ../restore-lab log --oneline --all
The restored lab displays its bundled commit history.
The clone creates an independent test checkout and log inspects its restored history.
Check coverage and privacy
A bundle contains Git objects selected by its references, not unstaged or untracked files, local configuration, hooks, reflogs or hosted pull-request metadata. Submodule repositories and external large-file content require separate treatment. It may also contain sensitive committed history. Store and transfer the bundle under the appropriate access and retention policy, and test every required companion asset.
Verify the restore procedure
In the lab, compare expected branch tips and a known file in the restored clone, then run an appropriate test. Separately test an incremental bundle against a recipient with and without its prerequisites. Record the commands, Git version, selected refs and missing categories without exposing private data. Repeat restoration periodically according to the ownerโs backup policy; creation alone is not recovery evidence.
Common errors and fixes
The restored checkout lacks an uncommitted file.
- Why it happens
- Bundles contain selected Git objects, not the working tree.
- How to fix it
- Preserve required uncommitted data through a separate approved process.
- Prevent it next time
- Document and test backup coverage.
An incremental bundle cannot be applied.
- Why it happens
- The recipient lacks prerequisite commits.
- How to fix it
- Provide the required base or a self-contained bundle.
- Prevent it next time
- Verify prerequisites in the recipient repository.
A bundle exposes sensitive history.
- Why it happens
- The transfer was treated as harmless source text.
- How to fix it
- Secure the artifact and follow the ownerโs incident process.
- Prevent it next time
- Classify content and restrict access before transfer.
2 practice exercises
1. Does --all include a new untracked local file?
Show worked solution
No. It selects refs for the bundle; untracked and unstaged working files are not committed Git objects. Preserve those separately if required.
2. Why test a clone rather than only creating a bundle?
Show worked solution
A fresh restore tests that the recipient can read the intended history. Compare required refs and companion data as well, because clone success alone cannot establish complete coverage.
Key takeaways
- Bundle selected Git history with a clear recipient contract.
- Check prerequisites and restore in an isolated directory.
- Handle uncommitted, external and sensitive data separately.