1

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 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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".
so I used git merge projectB/Main --allow-unrelated-histories after adding empty file then pushed it to projectA/Base

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.