-1

So I have a repository A. I want to push all the changes made (and the history) to another repository B. So, here's what i did:

  1. git clone [A URL]

  2. cd A // now i'm in the A directory (just to be clear)

  3. git remote add TeamRepo [B URL] // adds the B repository as a remote

  4. git push TeamRepo master // tries to push the changes to B repository

After last command, I have this error: fatal: refusing to merge unrelated histories Can anyone help me with this? I found some kind of related articles, but they did not help me at all

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Andrei Manolache
  • 766
  • 1
  • 8
  • 17
  • There is already commits and branches in that remote repository. Are you sure it was the *push* command that complained? I didn't think a push could cause a merge. In any case, if there is already commits and branches in that remote repository you need to decide how you want to reconcile that because you're mixing two repositories and as you can see, git doesn't allow you to do that by default because it can be a mess. Can you verify whether there is something in that repository, and if there is, what did you *want* to happen? – Lasse V. Karlsen May 17 '20 at 20:47
  • To clarify: repo A has some work done, repo B with a specific branch (let's call it Features) has nothing on it. I want to make a pull request on repo B Feature branch with all my work in repo A Master branch – Andrei Manolache May 17 '20 at 20:50
  • You can't have a branch without at least one commit. There are commits in repo B, you need to decide how to handle this situation. – Lasse V. Karlsen May 17 '20 at 21:01

1 Answers1

1

The “fatal: refusing to merge unrelated histories” Git error occurs when two unrelated projects are merged (i.e., projects that are not aware of each other’s existence and have mismatching commit histories).

You have created a new repository (TeamRepo), added a few commits to it, and now you are trying to pull/push from a remote repository that already has some commits of its own. Git will also throw the error in this case, since it has no idea how the two projects are related.

Solution: You can use --allow-unrelated-histories to force the push to happen. Documentation

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34