Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronize two Git repositories without direct connection

Tags:

git

I have two git repositories which I need to synchronize without having direct network connection between them.

I cannot use git fetch or git push as-is because both of them require that direct connection. Patchfiles also don't seem to be a viable option because they lose commit tree structure. Although, I've discovered that git uses git pack-objects and git unpack-objects under the hood to generate and consume pack-files.

Can I somehow make Git generate that packfile for me (given I provide commit range I want) and then consume it? Or maybe there's some way to preserve structure in patches? Or maybe there's some other approach?

Thanks

like image 830
Target-san Avatar asked Sep 15 '25 05:09

Target-san


1 Answers

Try git bundle.

A bundle works as a read-only repository. To create a bundle of the branch master,

git bundle create foo.bundle master

Then you can move foo.bundle to the machine where the other repository is and read/fetch the metadata you need.

cd <the_other_repository>
git checkout master
git pull <path_to_foo.bundle> master

# or maybe you want to cherry-pick a single commit
git fetch <path_to_foo.bundle> master
git cherry-pick <commit>
like image 138
ElpieKay Avatar answered Sep 17 '25 20:09

ElpieKay