Git - Refusing to merge unrelated histories

Every time I create a new blank project in GitHub and I try and merge in my local project to that new project I would do a git pull on the main repository while also being on main on my local.

git pull origin main

I often come across this error when trying to merge the origin main and local main branches.

unrelated-1.png

To fix add the --allow-unrelated-histories flag to git pull.

git pull origin main --allow-unrelated-histories

Here is the result with the command.

unrelated-2.png

At this point it’s a matter of fixing the merge conflict and then pushing the new change back to origin to add the new project files to GitHub.