Question

Here is the situation. I have a remote git repository on Server A. Also, I have to work on Desktop B with the same source code in this repository. Because of the limited bandwidth to access Server A, I'd like set up a local mirror on Desktop B for the repository.

Now, I have set up the mirror repository by

git clone --mirror https://repository-on-server-a /local/repo/path.git

I have tested the local repository by

git clone file://localhost/local/repo/path.git

Then I modified crontab to do

cd /local/repo/path git fetch -q

to sync up every 5 mins. It works well.

At the beginning, I was thinking about using

git config --global url.file://localhost/local/repo/path.git.insteadOf https://repository-on-server-a

to have git fetch all objects from local directory instead of a remote repo. However, it doesn't work.

My question is

  1. Is there a simple way to set up such local mirror for a remote git repo?
  2. How to handle 'git push'? Since the insteadOf will get every push into local directory, how could I push all my changes back to Server A?

The local directory is for a test but not the final solution. I will have another Desktop C to get source code from Desktop B later. Another colleague will join me too. That means we want to put all changes in Desktop B to have some 'centric' solution for us.

Was it helpful?

Solution

What's the mirror for? Your local git working directory already is a mirror of the origin repository; that's how DVCSes work. I don't understand the benefit of a second local copy on your filesystem.

EDIT If you want to use one of your repos as a local-network collection point for changes between the rest of your network and the upstream origin, then the cron job is fine. Just have it do a push --mirror after it does its fetch -a.

However, I wouldn't bother with the proxy/alias setup. Just have everyone clone from and push to your local mirror explicitly; that way it won't get in the way if they need to get to the real origin for some reason. They can even set both URLs as remotes, use the local one by default, and have the real one available by remote name if needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top