Git – Pull/Push with different repositories

Question:

I have a project that uploads to 2 repositories at the same time using the same remote, for example:

[remote "origin"]
url = https://gitlab.com/teste.git
url = http://bitbucket.org/teste.git

In this type of situation, when I want to pull the project, it will use which of the 2 links as a base?

Would there be any way to define which link I want to use when pulling?

I believe that it doesn't pull from the 2 repositories at the same time, because if there was a difference between them, an error or something like that would be pointed out.

Answer:

With this scenario you will have a problem, since the repositories that are at the source can have different commits.

A configuration that could be tried would be to have 3 origins, or better 3 remotes, one with two URL's and the other 2 remotes, each one configured with 1 URL's. This way you could send to 2 repositories, but to receive you could use first one remote and then the other, making your repository the centralizer of the merge.

Keeping a scenario this way is unnecessary if the objective is backup. The two URL's used as an example, at least, have great backup services. If the idea is to have redundancy of services in case of failure, there are other ways to synchronize the repos, which would be the simplest solution, but it is beyond the scope of this question.

Scroll to Top