Search code examples
gitgithubpushgit-remote

How to push changes made in a repository to another one


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


Solution

  • 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