I have met a problem several times before. When we build a new repository on GitHub, the official recommended steps are
- Build a new empty repo on GitHub
- Init local git directory
- Make the first commit
- Bind the remote repository URL
- Push your commits
While some time, the actual is we would init github repo with Readme.md
and .gitignore
, and forget to make the pull first and make the first commit. So here comes the problem, it will raise fatal: refusing to merge unrelated histories
.
At first, I always delete that dir and re-init the git dir.
After searching on the Internet, I found a solution on Stackoverflow
.
One git pull
option helps.
1
git pull origin branchname --allow-unrelated-histories
Through --allow-unrelated-histories
, we can force pull and merge unrelated changes later, if all changes were committed.