No master to my dev branch

Hi everyone, 

new git user here, been using it for about 4 months. I am not a developer, more of an integrator. I integrated extensions into Magento stores and perform basic customizations, hotfixes and deployment, and I work by myself.

When I started using Git, I figured I would use a basic workflow:

Master branch, pushed to github, holds production version of site

Dev branch, local only, ongoing development of site

Feature branches as needed

I must of ran a bad command in my very early days, because the master and dev branches that I have are apparently unrelated. When I run

git checkout master
git merge dev

I get the error:

fatal: refusing to merge unrelated histories

Since I was always in development and never in production, this is the first time I try to merge to Master. I know there is nothing special about the Master branch, it’s just a branch like any other, but how can I fix this situation?


Most repositories start from a single starting point. They diverge at various points when branches are born. They come back together when branches are merged. What you did is you created a repository that has two separate starting points, even though the two branches at various points may have had the same contents, as far as Git is concerned they are completely separate histories. Because this isn’t the standard way things work, now that you’re trying to merge these two separate histories it is giving you an error because it is assuming that you did something you didn’t intend to.

If you want to force the merge anyway, you can use the command git merge --allow-unrelated-histories dev.

1 Like

Thanks you for the insight. This was my understanding of how things worked.

The solution I was expecting was a wait to link a newly created Master branch to a specific commit (ie. the very 1st one). This is how I thought the unrelated branches would be “reconnected”. 

I will proceed in the way your describe. Just to confirm: the allow-unrelated-histories flag is only used once, and will not be needed again in the future, correct?