Just ran into this situation, and I’m leaving a note here for my future self. I hope you find it helpful.
I got myself into the chicken-or-the-egg situation that goes like this:
- Got this idea for a small app
- Okay, the first thing to do is to make a repo on github, right? I do that, and name the project
- Hmmm, I want to use Create React App to make most of the pain go away
- I run
npx create-react-app my-apps-namelocally but that makes a new directory all unto itself
- What to do?
- Oh, yeah, add a new remote
git remote add origin https://github.com/user/repo.git
git pull origin master…. well, crap.
fatal: refusing to merge unrelated histories
- Here is the magic command:
git pull origin master --allow-unrelated-histories
- Resolve merge conflict in the readme, push to the remote