GIT with multiple remotes in one project

Asked

Viewed 163 times

1

I have project A which is my main project. From this project was born project B, by "Fork". Wonderful, so I want to develop things in Project A and I want to replicate them for Project B. When I develop things in project A and commito push and everything beauty, then I go to project B that I cloned and added a new remote to it:

git remote add upstream url_projeto

I do:

git merge upstream/master

Wonder, come the changes, BUT some things aren’t coming. I don’t know pq, for example a folder with its respective files didn’t come.

And also on the other hand, I developed things in Project B that don’t exist in his father’s "Project A" and when I merge in Project B with Project A he goes and deletes some things even though they never existed in Project A.

It was clear it would be the problem?

1 answer

3

I think it is not so interesting to work on two projects on 2 remotes. (And if I understood the case, the project To has only 1 remote, while the project B has both). It is possible to use only 1 repository with 2 remotes, but will require certain care.

When the code git remote add upstream url_projeto is executed, git creates an internal reference to another repository (other than what already came in the clone), so it is possible to have "n" references. Example:

Adding remote with reference to github:

git remote add github https://github.com/userx/repox.git

Adding remote with reference to bitbucket:

git remote add bitbucket https://[email protected]:1234/repox/repo.git

Adding remote with reference to gitlab:

git remote add gitlab http://gitlab.com/usex/repox.git

As you can see, in the example I created 3 remotes for the same project (github, bitbucket, gitlab), and so I can work with the 3 at the same time.

Assuming more than one person has permission only on github, while another working on gitlab needs these modifications, but you as a system broker need to resolve the situation.

git fetch github master
git pull github
git push gitlab master
# Note que o remote sempre é especificado

Okay, now gitlab has been updated with the content of github. But it’s still quite complicated to manage these changes this way... I recommend that you only try to work with a remote, as it is possible that many problems occur, for example conflicts in which only the administrator can solve them.

  • Opa thanks for the answer. That’s how I’m using already, as I am administrator of the 2 projects has no problem. Just this bizarre bug where certain files that are created in the parent project (in this case A) when I pull it doesn’t come to the B project and I don’t know why.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.