0

I have repository A and repository B and I want to merge B into A meaning I want all of the files of B to be merged with the files of A (the files have the same names). I would expect to get a lot of conflicting files which I would first need to resolve before commiting the changes but instead every file is just getting committed to a subdirectory of A which is basically still the repository B, so to conclude, nothign actually changes. I could just copy and paste the folder of repository B into A and it would be the same.

I used the following strategy:

cd C:\repos\Repo_A
git remote add Repo_B <remote-link-to-RepoitoryB>
git fetch Repo_B
git checkout -b merge-branch Repo_B/master
git checkout master 
git merge merge-branch --allow-unrelated-histories

after I run the last command, I get the information that only .gitignore is running into a conflict. The rest of the files are "staged changes", which is not possible, because there are a lot of files that are different from repository A, but they are not getting conflicted nor merged together in some way.

this is what i get after the last command: enter image description here

this is the folder structure I get after using "git checkout -b merge-branch Repo_B/master": enter image description here

Note that everything gets pushed into B and nothing actually changes for my master branch in Rep_A. In the commit history it looks like everything got merged but nothing to the files actually changes inside the folder Repository_A.

How can i actually merge into a single directory, from which I can then work and consider to be the latest version of the project?

EDIT: this is the file structure of Repository_A (or folder): enter image description here

And here is the same for Repository_B inside A: enter image description here

  • Can you show "repos/Repository_A" and "repos/Repository_B" folder before the merge? – vernou Jun 09 '23 at 09:37
  • why would that matter if i may ask – Comfortable_Onion Jun 09 '23 at 12:20
  • 2
    I think you want merge `repos/Repository_B/Repository_B` in `repos/Repository_A/Repository_A`. It isn't a repository merge, but a folder merge. The file/folder arborescence can help to understand your problem. – vernou Jun 09 '23 at 12:55
  • Don't show all files, just some of them as example. – vernou Jun 09 '23 at 12:57
  • hey thanks for clarifying. I have just added two screenshots of the folders – Comfortable_Onion Jun 09 '23 at 13:20
  • 2
    Sound like you want merge folder, not repository. Maybe this can help : [Git merge between two folders, not branches](https://stackoverflow.com/questions/10091858/git-merge-between-two-folders-not-branches) – vernou Jun 09 '23 at 13:31

1 Answers1

0

the simple and rather obvious solution was to just make sure both repositories had the same folder structure or the same project name. That way when adding the repository to the original folder the files could get conflicted for git to be able to offer merging.

I know that sounds very obvious but it just didnt came to my mind that this would be solution. I spend hours researching this and nowhere did it say "make sure that the naming is the same in both repositories/folders". Is it that obvious for the other repository to have the same project-folder-name as the original?

To clarify: I just changed the project name and folder name of repos_B to repos_A and repeated the process I showed above. Worked fine