I have git repo servers at different locations around the country. When I move to one of those locations, I’d like to use the local server for push/pull. This is managed simply by modifying the .git/config and changing the origin branch. At the same time, I’d like all branches and tags pushed to that local server to be replicated across all the git repositories on other servers.
What is the best way to go about setting this up?
Should I modify the .git/config to include a remote “all” that has the url to each server? This way every time I do a git push all it will push to all servers.
Should I add in post-commit hooks to each git repo server to push to the other servers? This then requires no additional setup for the client side, as they simply need to push to any of the servers.
What about git clone --mirror? Will this help achieve the clustering effect?
You should do it server side as much as possible so as not to burden the committer with any overhead. You have to be careful about recursion with post commit hooks. If all servers push to all others on commit you can end up in a case where all severs continue to push to each other. However, you can use this to your advantage. Each server only needs to worry about the server to it’s virtual right. For example, A -> B -> C -> D -> … A. If each server has a post commit hook to first see if the next server is up to date and the push to it if not, push it then eventually all servers will be in sync. So server A pushed to B which pushes to C which pushes to D which checks to see that A is up to date so does nothing.
You’ll probably end up with edge cases this way and have to worry about pushes that fail to other servers, but the next commit will sync it up.
You can also just use rsync.