3

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

Target-san
  • 451
  • 3
  • 11
  • use a (bare, probably) repo on a usb and share it between the computers. – eftshift0 May 03 '19 at 13:41
  • Already answered in comments to https://stackoverflow.com/a/55971673/508023. ~500km distance. – Target-san May 03 '19 at 15:11
  • Please *read* initial question. Anyway, https://stackoverflow.com/a/55971126/508023 is precisely what I needed. – Target-san May 03 '19 at 15:20
  • Possible duplicate of [Synchronizing git repositories without access to each other and no access to both from any system](https://stackoverflow.com/questions/55616223/synchronizing-git-repositories-without-access-to-each-other-and-no-access-to-bot) – A.H. May 04 '19 at 21:09
  • Other duplicate: https://stackoverflow.com/q/55567263/947357 – A.H. May 04 '19 at 21:10

1 Answers1

4

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>
ElpieKay
  • 27,194
  • 6
  • 32
  • 53