Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clone git repository without network connection

The infrastructure: I have two hosts (A and B). I cannot connect from A to B or vice versa. There is no host C which is reachable from host A and host B. I can send e-mails in both directions. Text attachments are allowed. Others attachments are not allowed. There may be other problems ...

I want to clone a git repository from host A to host B. I want to be able to work on both hosts. I want to push my commits from A to B and vice versa.

Question: Is there a simple way to transfer commits (usable with my infrastructure)?

I have tried: I can use git format-patch to make text versions of my commits. But there is only the author date in the generated files. The committer date is missing. And the parent commit is missing. I can look at the other host - so I know both informations. And then, I can use git commit with GIT_AUTHOR_DATE and GIT_COMMITER_DATE to generate a commit with the correct commit-hash.

It works :) But I have to type a few commands. And if I want to transfer more commits, I have to type a few more commands.

like image 869
Shear Plane Avatar asked Feb 21 '26 06:02

Shear Plane


1 Answers

You could use git bundle to create an archive of refs. From the man page:

Create, unpack, and manipulate "bundle" files. Bundles are used for the "offline" transfer of Git objects without an active "server" sitting on the other side of the network connection.

They can be used to create both incremental and full backups of a repository, and to relay the state of the references in one repository to another.

Since the requirement is "text only", you could then hex- or base64 encode the bundle to get a text representation that can be reverted on the receiving host.

Another quick-and-dirty solution is to tar your repo and encode as text. Using this approach cannot do incremental updates for obvious reasons.

Both solutions avoid the problem of messing with committer and author information. Setting author == committer loses information if the original repository (on host A) contains commits with distinct author and committer information.

like image 162
knittl Avatar answered Feb 24 '26 11:02

knittl