Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a "git bundle create --all" in JGit?

Is it possible to bundle a repository using JGit?

I'm trying to do the equivalent of this git command:

git --git-dir=path/to/my/local/repo bundle create path/to/backup.bundle --all
like image 488
Pado Avatar asked Nov 08 '25 16:11

Pado


1 Answers

Looking at the documentation, I'd say yes:

public class BundleWriter
extends Object

Creates a Git bundle file, for sneaker-net transport to another system.

Here's an (untested) example:

Repository repo = new FileRepositoryBuilder()
    .setGitDir(new File("path/to/my/local/repo/.git"))
    .build();
BundleWriter bundle = new BundleWriter(repo);

for (Ref ref : repo.getRefDatabase().getRefs()) {
    bundle.include(ref);
}

bundle.writeBundle(
    new NullProgressMonitor(),
    new FileOutputStream("path/to/backup.bundle"));
like image 56
Enrico Campidoglio Avatar answered Nov 10 '25 08:11

Enrico Campidoglio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!