Created
September 21, 2019 19:25
-
-
Save tcodes0/92874d34f5a40fa0170de2c9bee45898 to your computer and use it in GitHub Desktop.
git merge two repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Using submodules - it's good if repos are unrelated or developed separately | |
| see http://www.kernel.org/pub/software/scm/git/docs/v1.5.6/git-submodule.html | |
| Either copy repository A into a separate directory in larger project B, or (perhaps better) clone repository A into a subdirectory in project B. | |
| Then use git submodule to make this repository a submodule of a repository B. | |
| Using subtree - real merge | |
| see http://nuclearsquid.com/writings/subtree-merging-and-you/ | |
| ``` | |
| cd into repo Aproject | |
| mkdir dir-B | |
| git remote add -f Bproject /path/to/B | |
| git merge -s ours --allow-unrelated-histories --no-commit Bproject/master | |
| git read-tree --prefix=dir-B/ -u Bproject/master | |
| git commit -m "Merge B project as our subdirectory" | |
| # this will trigger a rebase and you may need to fix conflicts | |
| git pull -s subtree Bproject master | |
| ``` | |
| At this point dit-B was gone but the repos merged. | |
| git log doesn't show commits for Bproject, but Bproject files have commit history. | |
| # source https://stackoverflow.com/questions/1425892/how-do-you-merge-two-git-repositories/10548919#10548919 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment