Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "refusing to merge unrelated histories" when uploading project to github?

I have installed Github desktop and git on windows machine, I got a github account and created a dummy repository.

When I intend to upload my package through git bash command line, it fails with error: fatal: refusing to merge unrelated histories

I used several ways to overcome this issues by using existing solution from this community, but still didn't fix the problem. Does anyone know any trick of working this problem? How can I upload my projects to github successfully?

like image 425
Hamilton Avatar asked Nov 09 '16 00:11

Hamilton


2 Answers

Just sharing that rebasing worked for me. I had a new project on GitHub, and a new repo locally that I wanted to link up, and kept getting fatal: refusing to merge unrelated histories. What worked:

git remote add origin http://github.com/MyName/MyProjectName -f
git branch -u origin/master
git pull -r     # R for rebase, makes the magic happen

Output:

First, rewinding head to replay your work on top of it...
Applying: Initial Commit

git log output (1st is GitHub repo, 2nd is local):

c7f843e Initial Commit (AmitaiB, 4 minutes ago)
97100be Initial commit (Amitai Blickstein, 9 minutes ago)

PS Funny, I never noticed that the default initial commit message from GitHub is Initial Commit, whereas the local one is Initial commit (lowercase). I think I'll send that question in to Jack Handy...

like image 62
AmitaiB Avatar answered Oct 28 '22 03:10

AmitaiB


Try the following:

cd /path/to/my/repo
git init
git add --all
git commit -m "Initial commit"
git remote add origin <remote repo URL>
git push -u origin master

Be sure to replace /path/to/my/repo with path to your repo directory(e.g. C:\Users\jvrat\Documents\MSPC), and <remote repo URL> with URL to your remote repo (e.g. https://github.com/username/repo_name.git).

like image 33
TeWu Avatar answered Oct 28 '22 04:10

TeWu