git bundle: Package objects and references into an archive

The git bundle command in Git allows you to package a set of Git objects and references into a single file, known as a bundle. This bundle contains the complete history of a Git repository, including commits, trees, and blobs, as well as branch and tag references.

The primary use case for git bundle is to facilitate the exchange of Git data between repositories in a compressed and portable format. It is particularly useful in scenarios where direct network connectivity between repositories is limited or unavailable. Bundles can be shared via removable storage devices or transmitted over other transfer protocols like email or file sharing services.

To create a bundle, you specify a range of commits or a set of references that you want to include. The bundle file can be created using the git bundle create command, followed by the name of the bundle file and the range or references to include. For example:

# git bundle create myrepo.bundle master branchA

This command creates a bundle named myrepo.bundle that includes the history of the master branch and branchA.

Once a bundle is created, it can be transferred to another repository or stored for later use. To incorporate the contents of a bundle into a repository, you can use the git bundle unbundle command. This command fetches the objects and references from the bundle file and adds them to the repository. For example:

# git bundle unbundle myrepo.bundle

This command retrieves the objects and references from the myrepo.bundle bundle file and incorporates them into the current repository.

Using git bundle, you can conveniently package and transport Git data, allowing you to share repository history with others or create backups of repositories. It provides a flexible and portable way to exchange Git data, even in situations where direct network access is not feasible.

It’s important to note that git bundle does not sync or update repositories automatically. It is your responsibility to manage the exchange and incorporation of bundle files into repositories as needed.

git bundle Command Examples

1. Create a bundle file that contains all objects and references of a specific branch:

# git bundle create /path/to/file.bundle branch_name

2. Create a bundle file of all branches:

# git bundle create /path/to/file.bundle --all

3. Create a bundle file of the last 5 commits of the current branch:

# git bundle create /path/to/file.bundle -5 HEAD

4. Create a bundle file of the latest 7 days:

# git bundle create /path/to/file.bundle --since=7.days HEAD

5. Verify that a bundle file is valid and can be applied to the current repository:

# git bundle verify /path/to/file.bundle

6. Print to the standard output the list of references contained in a bundle:

# git bundle unbundle /path/to/file.bundle

7. Unbundle a specific branch from a bundle file into the current repository:

# git pull /path/to/file.bundle branch_name
Related Post