Pushing to multiple git URLs with set-url and its pitfalls

南楼画角 提交于 2019-12-08 03:28:09

问题


I want to setup a gitlab server on my local server and also use gitlab cloud as an offsite backup. Whenever a developer pushes their work i want it to go to both gitlab servers. I will do this using the following git commands

git remote set-url --add --push origin git://my_local_repo_url
git remote set-url --add --push origin git://my_gitlab_com_repo_url

I am concerned though that the two servers could go out of sync easily.

  1. What would happen if one of the servers was down during the push so one succeeded and one failed? How would i handle this?
  2. What if a developer forgot to add one of the remote URLs so only one of the servers was being pushed to and then the second remote URLs was added. What would happen the next push and how would i handle it?
  3. What other problems might I run into?

回答1:


What would happen if one of the servers was down during the push so one succeeded and one failed? How would I handle this?

As mentioned in "pull/push from multiple remote locations", a failed push (because one of the remote repos, for any reason, was not available) can be fixed at the next push: the commits which were not pushed last time are pushed (in addition of the new ones) in the next push.

Even of the developer add the second remote later, as long as that second remote reflect what is in the first, that is OK: only new commits will be pushed (to both)

But the problem is:

  • divergent history (when one of the remote has commits that you do not have yet): you need to rebase on top of origin/master (in a fetch, origin always refer to the first url): then you can push
  • divergent remote (when both remote have different set of commits, because of two different history pushed to each one): you would need to push --force to one of those remote in order to rewrite/reset its history.


来源:https://stackoverflow.com/questions/43426524/pushing-to-multiple-git-urls-with-set-url-and-its-pitfalls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!