1

Someone created an empty GitHub repo for me and added a README.md file in it. In the meantime I started working on my project.

Now I want to start pushing on this repo so I did git init followed by git remote add origin https://github.com/whatever/my_project.git.

But then when I do git pull origin master to get sync with the repo and start pushing to it, I get this error message:

* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories

Why and how to solve this problem?

drake035
  • 3,955
  • 41
  • 119
  • 229

1 Answers1

3

This is because both the github repo and the local repo have initial commits with no parent. It cannot reconcile how to connect them. What I would do in this situation is manually copy the readme to my local repo and do a force push:

git push -f origin master
captncraig
  • 22,118
  • 17
  • 108
  • 151
  • That sounds like a hack to me, is there a non-hacky way or is that the only way? – drake035 May 04 '17 at 21:21
  • Yeah, see answers in linked question. – captncraig May 04 '17 at 21:21
  • 1
    I actually prefer the forced-push for this particular situation - there is no reason to clutter up the repository with the default GitHub `README.md`-only commit. You might want to add this answer to that question. (Also, "force push" seems appropriate for May the 4th... :-) ) – torek May 04 '17 at 21:22
  • Good idea. Did that. – captncraig May 04 '17 at 21:24