15

I've added a remote repository to the folder where I am working with:

git remote add origin https://github.com/<username>/<repo>.git

If I type:

git pull origin master

I get:

From https://github.com/<username>/<repo>
    * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

I have also tried:

git pull origin master --allow-unrelated-histories

But I get:

From https://github.com/...
    * branch            master     -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
    <files>
Please commit your changes or stash them before you merge.
Aborting
5

1 Answer 1

54

You need to either reset or commit your changes first:

git reset --hard

or:

git commit -m "saving changes..."

Then you can do:

git pull origin master --allow-unrelated-histories
Sign up to request clarification or add additional context in comments.

2 Comments

I had the same problem and the command below solved it. git pull origin master --allow-unrelated-histories I created a github repo (with one default file commited) and after that I created a local repository. So, the repos (remote and local) started independently and with different contents. That´s why --allow-unrelated-histories is necessary. IMHO, this issues must be closed.
I have an annoying fatal: refusing to merge unrelated histories

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.