How to synchronize two git repositories

Rather than making a bare clone, I prefer making a bundle (see “How can I email someone a git repository?“), which generates one file, easier to copy around (on an USB stick for instance).

The bonus is that it does have some of the characteristics of a bare repo: you can pull from it or clone it, but you only have to worry about one file.

machineB$ git clone /home/me/tmp/file.bundle R2

This will define a remote called “origin” in the resulting repository that lets you fetch and pull from the bundle. The $GIT_DIR/config file in R2 will have an entry like this:

[remote "origin"]
    url = /home/me/tmp/file.bundle
    fetch = refs/heads/*:refs/remotes/origin/*

To update the resulting mine.git repository, you can fetch or pull after replacing the bundle stored at /home/me/tmp/file.bundle with incremental updates.

After working some more in the original repository, you can create an incremental bundle to update the other repository:

machineA$ cd R1
machineA$ git bundle create file.bundle lastR2bundle..master
machineA$ git tag -f lastR2bundle master

You then transfer the bundle to the other machine to replace /home/me/tmp/file.bundle, and pull from it.

machineB$ cd R2
machineB$ git pull

Leave a Comment