Reputation: 1
I'd like to ask if anyone tried working with this scenario.
I have 2 different source controls. The first source control repository is the parent while the second repository is the child. Both repositories have the same project and has its own remote repo but the child has more updated files compare to the parent. I'm planning to merge the child to the parent but the problem is, they are different repositories. Any help?
Upvotes: 0
Views: 138
Reputation: 265966
This answer assumes that both your repository share a common history, i.e.
A commit in Git always references its direct parent or parents. It does not matter whether a commit is part of repository A or B. Usually, such repositories are called fork (cf. GitLab or GitHub UIs), but for Git it does not really matter.
Therefore, to merge the history of two repositories, add one to the other as remote, then merge the history (just like you would with a regular branch):
git clone server.com/repoA
cd repoA
git add remote b server.com/repoB
git fetch b
git merge b/branch_to_merge
After git fetch b
your local clone will contain the history of both repositories: history of A in implicit remote origin
, history of B in remote b
. git merge b/branch_to_merge
then merges the branch of repository b into your current branch of your clone (most likely master
or main
). Make sure to switch branches beforehand if you need to merge into a different branch.
To visualize the history, you could run gitk --all
right after the fetch step to see how the commits of both repositories are related.
Upvotes: 1