Git – Merge Unrelated histories

I have a set of code which worked on before but never version controlled. I was trying to push it to Github by creating a new repo on Github with some git ignore config files and, then initialize, add and commit the local repo with:

However when I try to pull from the remote repo on Github, an error was raised:

And then I realized, since git 2.9, the default behaviour of merging two unrelated repo has been changed:

“git merge” used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history merged into the existing project. The command has been taught not to allow this by default, with an escape hatch --allow-unrelated-histories option to be used in a rare event that merges histories of two projects that started their lives independently.

To work around this, I took the suggestion and used the flag:

in my command:

And the issue was resolved and the remote and local worked were merged fine, so I was able to push my local code to Github.

Leave a Reply

Your email address will not be published. Required fields are marked *