Git Bundle and Archive

Updated · 11 min read
mediumGit 2.53gitbundlearchivenotesofflinebackup

A bundle is a single file that contains Git commits and the branches and tags that point to them, in the same format Git uses to send data over the network. You can copy it on a USB drive or attach it to an email, and someone else can clone or fetch from it as if it were a remote repository. It is used to move a repository, or a batch of new commits, between computers that can't reach a common server, and to keep a complete backup in one file.

An archive, made with git archive, is something different: a zip or tar file of the project's files at one commit, without any history. It is used to hand over a release's source code to people who don't need Git.

Think of moving house. A bundle is the whole house packed into one container, ready to be unpacked somewhere else exactly as it was. An archive is a photograph of the living room on one day.

Syntax

Terminal
git bundle create <file> <refs>...
git bundle verify <file>
git clone <file> <folder>
git archive --format=<zip|tar> -o <file> <commit>
CommandDescription
git bundle create <file> --allIt is used to put every branch and tag, with all history, into one file.
git bundle create <file> <branch>It is used to bundle one branch.
git bundle create <file> <old>..<branch>It is used to bundle only commits newer than old (an incremental bundle).
git bundle verify <file>It is used to check that a bundle is complete and can be used by this repository.
git bundle list-heads <file>It is used to list the branches and tags inside a bundle.
git clone <file> <folder>It is used to create a repository from a bundle.
git fetch <file> <branch>It is used to bring commits from a bundle into an existing repository.
git archive --format=zip -o <file> <commit>It is used to export the files of one commit as a zip (or tar, tar.gz) file.

The Starting Point

Terminal
mkdir fee-tracker
cd fee-tracker
git init --quiet
echo 'Term 1 fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
echo 'Late fee: $250' >> fees.txt
git commit --quiet -am "Add the late fee"
git tag -a v1.0 -m "Fee Tracker 1.0"
git switch --quiet -c feature/hostel-fee
echo 'Hostel fee: $9,000' >> fees.txt
git commit --quiet -am "Add the hostel fee"
git switch --quiet main
git log --oneline --all
Output
b8c0f38 (feature/hostel-fee) Add the hostel fee
d363415 (HEAD -> main, tag: v1.0) Add the late fee
6b651a0 Add the term fee

Example 1: Bundling the Whole Repository

Navika's school computer has no internet access. She packs the repository into a file to take it home:

Terminal
git bundle create ../fee-tracker.bundle --all
git bundle verify ../fee-tracker.bundle
Output
The bundle contains these 4 refs:
b8c0f38c59179627741e4ac1c818570553f49015 refs/heads/feature/hostel-fee
d3634159d792a8580d716faa354dcd8dadb2eaa1 refs/heads/main
36e68418d9d90834ed7ed5e0d1b4453b9c115785 refs/tags/v1.0
d3634159d792a8580d716faa354dcd8dadb2eaa1 HEAD
The bundle records a complete history.
The bundle uses this hash algorithm: sha1
../fee-tracker.bundle is okay

Explanation: --all put every branch and tag in the bundle. git bundle verify lists the references inside (HEAD too, so that a clone knows which branch to check out) and says the bundle is okay. It "records a complete history", because it doesn't depend on any commits the receiving side must already have.

At home, she clones from the file:

Terminal
cd ..
git clone --quiet fee-tracker.bundle home
cd home
git log --oneline --all
git remote -v
Output
b8c0f38 (origin/feature/hostel-fee) Add the hostel fee
d363415 (HEAD -> main, tag: v1.0, origin/main, origin/HEAD) Add the late fee
6b651a0 Add the term fee
origin	/home/navika/projects/fee-tracker.bundle (fetch)
origin	/home/navika/projects/fee-tracker.bundle (push)

Explanation: the clone has every commit, the tag and both branches (as origin/...). Its origin is the bundle file. A bundle is a read-only remote: you can clone and fetch from it, but not push to it.

Example 2: An Incremental Bundle

Back at school, Navika commits more work. Instead of bundling everything again, she bundles only the commits that are new since the last bundle, which ended at main = v1.0:

Terminal
cd ../fee-tracker
echo 'Exam fee: $800' >> fees.txt
git commit --quiet -am "Add the exam fee"
git bundle create ../update.bundle v1.0..main
git bundle list-heads ../update.bundle
Output
cb5b85c6783a3eea0c22b1e8acc53576b592f4a1 refs/heads/main

Explanation: v1.0..main means "the commits on main that aren't in v1.0", so the bundle has just one commit. Such a bundle needs the receiving repository to have v1.0 already. git bundle verify in a repository without it says which commit is missing.

At home, she fetches from it:

Terminal
cd ../home
git bundle verify --quiet ../update.bundle
git fetch --quiet ../update.bundle main:refs/remotes/origin/main
git log --oneline origin/main
Output
../update.bundle is okay
cb5b85c (origin/main, origin/HEAD) Add the exam fee
d363415 (HEAD -> main, tag: v1.0) Add the late fee
6b651a0 Add the term fee

Explanation: with --quiet, verify printed only its verdict: the home repository has everything the bundle needs. git fetch with the bundle as the remote and main:refs/remotes/origin/main as the refspec (see "Working with Several Remotes") updated origin/main. She can now git merge origin/main as usual.

Example 3: Exporting a Snapshot with git archive

For the school office, Navika exports the 1.0 release as a zip file, with no .git folder and no history:

Terminal
cd ../fee-tracker
git archive --format=zip --prefix=fee-tracker-1.0/ -o ../fee-tracker-1.0.zip v1.0
unzip -Z1 ../fee-tracker-1.0.zip
git archive --format=tar.gz --prefix=fee-tracker-1.0/ -o ../fee-tracker-1.0.tar.gz v1.0
tar -tzf ../fee-tracker-1.0.tar.gz
Output
fee-tracker-1.0/
fee-tracker-1.0/fees.txt
fee-tracker-1.0/
fee-tracker-1.0/fees.txt

Explanation: both files contain only fees.txt as it was in v1.0, inside a folder fee-tracker-1.0/ (from --prefix; the trailing / matters). unzip -Z1 and tar -tzf list the contents. Only committed files are included: uncommitted changes and untracked files never end up in an archive, which makes it a reliable way to package a release. Files marked export-ignore in .gitattributes are left out (see "Git .gitattributes and Line Endings").

Notes on Commits

git notes attaches extra text to a commit without changing it (changing the message would change its ID). It is used for things like test results, review sign-offs or "deployed to production on this date", added after the fact:

Terminal
git notes add -m "Approved by the school office" "v1.0^{}"
git log -1 v1.0
git notes list
Output
commit d3634159d792a8580d716faa354dcd8dadb2eaa1 (tag: v1.0)
Author: Navika Anamaneni <navika@example.com>
Date:   Mon Jan 5 10:08:00 2026 -0600
 
    Add the late fee
 
Notes:
    Approved by the school office
faa3c5509941943bebc3c16aa1b8b081639e7264 d3634159d792a8580d716faa354dcd8dadb2eaa1

Explanation: v1.0^{} means "the commit the tag points to". Without ^{}, the note would be attached to the annotated tag object itself, and git log wouldn't show it. git log shows the note under the message, the commit's ID is unchanged, and git notes list prints the note's own object ID followed by the commit it belongs to. Notes are stored on their own reference, refs/notes/commits, so they aren't pushed or fetched by default: share them with git push origin refs/notes/commits and fetch them with git fetch origin refs/notes/commits:refs/notes/commits. Few teams use notes, and hosting platforms don't show them, so treat them as optional.

Bundle, Archive, Patches or Clone?

NeedUse
Move the whole repository, with history, without a servergit bundle create <file> --all
Send new commits to someone who has the older onesAn incremental bundle, or git format-patch (see "Git Patches")
Hand over the source of a release, without Gitgit archive
A backup of a repository in one filegit bundle create <file> --all
Normal team workPush and fetch through a server
Four ways to move a repository's content

Common Mistakes

Expecting git archive to include history. It holds only the files of one commit. Use a bundle for history.

Forgetting the trailing / in --prefix. --prefix=fee-tracker puts files at fee-trackerfees.txt.

An incremental bundle the other side can't use. It needs the commits before the range. Run git bundle verify on the receiving side first.

Trying to push to a bundle. Bundles are read-only. Create a new bundle instead.

Expecting uncommitted work in an archive or bundle. Both contain only commits. Commit first.

Under the Hood

A bundle file is a short text header followed by a packfile. The header starts with a signature line (# v2 git bundle or # v3 git bundle), then lists prerequisites (commits the receiver must already have, each line starting with -) and the references in the bundle (<id> refs/heads/main), then an empty line. After that comes a normal packfile with every object needed, exactly as git fetch would receive it. That is why Git can clone and fetch from it with the usual commands. git archive, by contrast, reads one commit's tree and writes its files into a zip or tar format, storing the commit ID in the archive's comment (zip) or a header (tar), so git get-tar-commit-id can tell which commit a tar file came from.

Interview Corner

What is a Git bundle?

A single file containing commits and references, in Git's network format. You can clone or fetch from it like a remote, which makes it useful for moving repositories without a shared server, and for backups.

How do you send only new commits as a bundle?

Create it with a range, such as git bundle create update.bundle v1.0..main. The receiver needs the commits before the range, which git bundle verify checks.

What is the difference between git bundle and git archive?

A bundle contains history and references and is used with Git. An archive is a zip or tar of one commit's files, with no history, for people who don't use Git.

How do you export a release as a zip file?

git archive --format=zip --prefix=project-1.0/ -o project-1.0.zip v1.0.

Practice

Challenge: a one-branch bundle. In Navika's fee-tracker, create a bundle with only the branch feature/hostel-fee, list its heads, clone it into a folder review with that branch checked out, and print the clone's current branch and log.

What does Git print? Before you open the solution, decide why the clone needs -b here.

Show solution
Terminal
git bundle create --quiet ../hostel.bundle feature/hostel-fee
git bundle list-heads ../hostel.bundle
cd ..
git clone --quiet -b feature/hostel-fee hostel.bundle review
git -C review branch --show-current
git -C review log --oneline
Output
b8c0f38c59179627741e4ac1c818570553f49015 refs/heads/feature/hostel-fee
feature/hostel-fee
b8c0f38 (HEAD -> feature/hostel-fee, origin/feature/hostel-fee) Add the hostel fee
d363415 Add the late fee
6b651a0 Add the term fee

The bundle has one reference, refs/heads/feature/hostel-fee, and no HEAD, because only --all or naming HEAD adds it. Without -b, the clone wouldn't know which branch to check out, and would warn "remote HEAD refers to nonexistent ref, unable to checkout". With -b feature/hostel-fee, it checks out that branch, with its whole history.

Checkpoint. Bundle one of your repositories with --all, copy the file to another folder or computer, clone it, and compare git log --oneline --all in both.

Quick check: bundle and archive

4 questions
1Which command packs every branch and tag of a repository into one file?
2What does git archive include?
3How do you use a bundle file in an existing repository?
4Where are notes stored?

Key Takeaways

Quick reference

CommandIt is used to
git bundle create <file> --allBundle a whole repository
git bundle create <file> <old>..<branch>Bundle only new commits
git bundle verify <file>Check a bundle
git clone <file> <folder>Clone from a bundle
git archive --format=zip --prefix=<dir>/ -o <file> <commit>Export a snapshot
git notes add -m "<text>" <commit>Add a note

Was this tutorial helpful?

Lesson 94 of 106