Adding A repository to B repository in GitHub

16 Views Asked by At

I have a A repository with a react-app and B repository with some ML codes in Github. Both repository have some commits and i want to preserve my commits in A repository and add it to the B repository. So i can continue committing on B Repository (ML). How can i do this?

I was trying to add my file to the B repository normally but it doesn't preserve commits.

1

There are 1 best solutions below

0
Ricardo Gellman On

Clone your Repository B

git clone <repository B URL>

Navigate into the cloned Repository B directory and add Repository A as a remote.

cd <repository B directory>
git remote add repoA <repository A URL>

Fetch the commits from Repository A.

git fetch repoA

Merge the commits from Repository A into Repository B's main branch

git merge repoA/main  # or the branch from Repository A you want to merge

If there are any conflicts between the commits from Repository A and the existing code in Repository B, resolve them manually. Also keep directory structure compatible

git commit -m "Merge commits from Repository A"

Push the changes to Repository B.

git push origin main  

Now, you can continue working on Repository B and commit changes as usual.