0

I have two repositories repo-A and repo-B. I want to move repo-A into repo-B as a subfolder. My question is different from the possible duplicate answer! Please don't mark it without any thinking. I did the following in repo-B by following this:

git remote add repo-A url-to-repo-A
git fetch repo-A --tags
git merge --allow-unrelated-histories repo-A/master

However, I got the following error:

Auto-merging package.json
CONFLICT (add/add): Merge conflict in package.json
Auto-merging package-lock.json
CONFLICT (add/add): Merge conflict in package-lock.json
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

How can I solve this?

Alex Wang
  • 391
  • 2
  • 12
  • Possible duplicate of [How to resolve merge conflicts in Git](https://stackoverflow.com/questions/161813/how-to-resolve-merge-conflicts-in-git) – AElMehdi Oct 06 '19 at 13:12

1 Answers1

0

Question: Are the files in the two repositories A and B supposed to be the same files? Or do you want all the files in A to be added as a subdirectory and kept as separate files?

solution 1: Yes, they are the same files and those files need to be merged. In this case, you need to edit the files to resolve any conflicts. Conflict markers <<< and >>> will be added to the files. You need to edit the files so that they contain the content as you want them to be after merging. Then execute:

git add <file>
# after all file conflicts have been resolved and added
git commit

Solution 2: No, the files from repo A should all be in a separate subdirectory and kept separate from the files originally in repo B. In this case, you want to import repo A into repo B as a subtree. Use the git subtree command:

git subtree add -P <prefix> <repository> <ref>

for example:

git subtree add -P repo-A-dir url-to-repo-A master
David Sugar
  • 794
  • 4
  • 6