TIL - Git bundle

Posted by Marcus Folkesson on Saturday, July 13, 2024

TIL - Git bundle

TIL, Today I Learned, is more of a "I just figured this out: here are my notes, you may find them useful too" rather than a full blog post

The git bundle [1] subcommand has been around for many years but is something I came across quite recently.

The command allows you to create, unpack, and manipulate bundles files, which are used to share git repositories without an active server. Think of it as just a git repository packed into a tar archive with a set of handy extras.

My use case for this was that I had to share a repository using an encrypted USB drive.

/media/git-bundle.png

Create a bundle

Use git bundle create to create a bundle file:

1$ git bundle create myrepo.bundle master 
2Enumerating objects: 3, done.
3Counting objects: 100% (3/3), done.
4Writing objects: 100% (3/3), 220 bytes | 220.00 KiB/s, done.
5Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)

It is possible to include as many refs (branches, tags) as you like. If you want a full mirror of your repository you could use the --all argument.

Incremental bundles

It is also possible to create incremental bundles. To create a bundle containing all commits from version 1.0 to the master branch:

1$ git bundle create update.bundle v1.0..master 

You may then create a new remote pointing to update.bundle and do a regular git pull.

Verify a bundle

Use git bundle verify to check the content of a bundle:

1$ git bundle verify myrepo.bundle
2The bundle contains this ref:
3d76908b1e58f975fcc807b8c84fc0b28df603717 refs/heads/master
4The bundle records a complete history.
5The bundle uses this hash algorithm: sha1
6myrepo.bundle is okay

Clone from a git bundle

Use bundles as any remote:

1$ git clone myrepo.bundle
2Cloning into 'myrepo'...
3Receiving objects: 100% (3/3), done

This will creae a repository with all its content and point the origin remote to the bundle file:

1$ git remote  -v
2origin	myrepo.bundle (fetch)
3origin	myrepo.bundle (push)

Be aware of that bundles are read-only. You cannot push back content to a bundle.