How do you merge two Git repositories?

后端 未结 23 3342
耶瑟儿~
耶瑟儿~ 2020-11-21 05:45

Consider the following scenario:

I have developed a small experimental project A in its own Git repo. It has now matured, and I\'d like A to be part of larger projec

23条回答
  •  無奈伤痛
    2020-11-21 06:11

    If both repositories have same kind of files (like two Rails repositories for different projects), you can fetch data of the secondary repository to your current repository:

    git fetch git://repository.url/repo.git master:branch_name
    

    and then merge it to current repository:

    git merge --allow-unrelated-histories branch_name
    

    If your Git version is smaller than 2.9, remove --allow-unrelated-histories.

    After this, conflicts may occur. You can resolve them for example with git mergetool. kdiff3 can be used solely with keyboard, so 5 conflict file takes when reading the code just few minutes.

    Remember to finish the merge:

    git commit
    

提交回复
热议问题