I am building project A which uses code from Project B. each project is on different repositories. what I want is to clone the "Main" branch in project B then make a branch "Base" on project A. if some issues got solved in branch "Main" in project B I want to be able to pull it in "Base" in project A. I want to keep two branches in different repositories in sync.
1 Answer
You can do this but it might cause some collisions if the two projects happen to share unrelated files under the same paths.
First, add project B as a remote in project A:
git remote add projectB [email protected]:example/projectB.git git fetch projectB Then, set the upstream branch of "Base" in project A to branch "Main" from project B, like so:
git branch --set-upstream-to=projectB/Main Base Whenever you git pull when working on branch Base, git will pull in changes from branch Main in projectB.
Instead of this approach, consider submodules.
2 Comments
Amr Khalil
well I have empty projectA, I run command these commands in order
git remote add origin https://github.com/user/projectA.git,git checkout -b Base, then I run your 3 commands after git branch --set-upstream-to=projectB/Main Base I get this message "branch 'base' does not exist".Amr Khalil
so I used
git merge projectB/Main --allow-unrelated-histories after adding empty file then pushed it to projectA/Base