Minhajul Anwar's Blog

Git Merge Your Repo With Your GitHub Repo(both started seperately)

Git Merge Your Repo With Your GitHub Repo(both started seperately)

2021, Aug 01    

You started coding your projects locally, and created its git repo(not empty) seperately initiated with README and LICENSE files.


So before you merge, this are basically two projects and hence git refuse to mergeby default with a git pull.


If your GitHub repo was created as blank i.e., without any files that it wouldn’t be a problem. But now your local repo has your initial codes and GitHub repo has README and LICENSE files.


And git pull shows the error

fatal: refusing to merge unrelated histories

Of course you can solve this with either

  • Go back, create empty repo at GitHub
  • Go back, create GitHub repo with the initial files, then clone/pull it and then add your initial codes in the local repo

But if you think like me(no going back, do with what I’m with now), the solution is simpler. Use the flag –allow-unrelated-histories for git-pull.
So with your initial local codes committed, get your remote repo files(README and LICENSE) with

git pull --allow-unrelated-histories origin main