Home Explore Blog CI



git

3rd chunk of `Documentation/git-bundle.adoc`
23663cfb284d32db974e16ffc52d6fb7fb8f8f147142d0f50000000100000e4b
 next) | git bundle create master-and-next.bundle --stdin
----------------

And so are these (and the same but omitted `--stdin` examples):

----------------
$ git bundle create recent-master.bundle master~10..master
$ git bundle create recent-updates.bundle master~10..master next~5..next
----------------

A revision name or a range whose right-hand-side cannot be resolved to
a reference is not accepted:

----------------
$ git bundle create HEAD.bundle $(git rev-parse HEAD)
fatal: Refusing to create empty bundle.
$ git bundle create master-yesterday.bundle master~10..master~5
fatal: Refusing to create empty bundle.
----------------

OBJECT PREREQUISITES
--------------------

When creating bundles it is possible to create a self-contained bundle
that can be unbundled in a repository with no common history, as well
as providing negative revisions to exclude objects needed in the
earlier parts of the history.

Feeding a revision such as `new` to `git bundle create` will create a
bundle file that contains all the objects reachable from the revision
`new`. That bundle can be unbundled in any repository to obtain a full
history that leads to the revision `new`:

----------------
$ git bundle create full.bundle new
----------------

A revision range such as `old..new` will produce a bundle file that
will require the revision `old` (and any objects reachable from it)
to exist for the bundle to be "unbundle"-able:

----------------
$ git bundle create full.bundle old..new
----------------

A self-contained bundle without any prerequisites can be extracted
into anywhere, even into an empty repository, or be cloned from
(i.e., `new`, but not `old..new`).

It is okay to err on the side of caution, causing the bundle file
to contain objects already in the destination, as these are ignored
when unpacking at the destination.

If you want to provide the same set of refs that a clone directly
from the source repository would get, use `--branches --tags` for
the `<git-rev-list-args>`.

The 'git bundle verify' command can be used to check whether your
recipient repository has the required prerequisite commits for a
bundle.

EXAMPLES
--------

We'll discuss two cases:

1. Taking a full backup of a repository
2. Transferring the history of a repository to another machine when the
   two machines have no direct connection

First let's consider a full backup of the repository.  The following
command will take a full backup of the repository in the sense that all
refs are included in the bundle:

----------------
$ git bundle create backup.bundle --all
----------------

But note again that this is only for the refs, i.e. you will only
include refs and commits reachable from those refs.  You will not
include other local state, such as the contents of the index, working
tree, the stash, per-repository configuration, hooks, etc.

You can later recover that repository by using for example
linkgit:git-clone[1]:

----------------
$ git clone backup.bundle <new directory>
----------------

For the next example, assume you want to transfer the history from a
repository R1 on machine A to another repository R2 on machine B.
For whatever reason, direct connection between A and B is not allowed,
but we can move data from A to B via some mechanism (CD, email, etc.).
We want to update R2 with development made on the branch master in R1.

To bootstrap the process, you can first create a bundle that does not have
any prerequisites. You can use a tag to remember up to what commit you last
processed, in order to make it easy to later update the other repository
with an incremental bundle:

----------------
machineA$ cd R1
machineA$

Title: Git Bundle Examples and Use Cases
Summary
The git bundle command can be used to create self-contained bundles of Git objects and refs, allowing for transfer and recovery of repository data. Examples include creating a full backup of a repository, transferring history between machines without a direct connection, and using bundles to bootstrap and update repositories. The command provides options for specifying revisions, references, and prerequisites, and can be used in conjunction with other Git commands, such as git clone and git rev-parse, to manage and manipulate Git data.