I have two servers running git, one main instance with gitorious installed and another one on a cloud. I would like to keep them equal. Each push that I perform on my local machine should go to both servers or the main server sync with the cloud. How can I do it? Is there any simple way? Should it be done in my local machine or in the main server?
I have two servers running git, one main instance with gitorious installed and another
Share
You can add multiple URLs to a single remote. What you would need to do is, on your local machine, first create a remote corresponding to the gitorious server:
You’ll have to re-add the URL of the gitorious server as an explicit push URL:
and then do the same for the cloud server:
This should set up a configuration where every time you execute
git pushlocally, your changes will be pushed to both servers. But when you rungit pull(orgit fetch), it will only fetch from the gitorious server. This should be all that is needed, if the servers are to stay in sync.If you only ever push to either server from this one particular local machine, then that’s all you need. But if you push to one or the other server from any other computers, you will need to do the same configuration on each of those other computers. If there are enough computers that this gets unwieldy, or if other people have write access to the two repositories and you don’t absolutely trust them to get the configuration right, you’re probably better off doing something server-side. This would be the post-receive hook method that manojlds mentioned. To be clear, if you are using the post-receive method, do not use the dual-URL remote method described in the earlier part of my post.