1
votes

when trying to pull an existing repo from GitHub, git shows the following error:

$ git pull calc master From
https://github.com/predator2v0/simple-Javascript-calculator
* branch master -> FETCH_HEAD fatal: refusing to merge unrelated histories

I want to know how this happens and how to overcome it. do not have any issues if unrelated histories are merged. just want to know how to do that thing. please help.

1
what were you trying to do looks like you are pulling one repo into another maybeShubham Srivastava
yes, actually I added files previously to the remote repo via upload. and now after fixing some bugs in the local copy I tried to push it using git. and faced this problem. I'm new to git, so need help. thank you.predator2v0
thank you @ShubhamSrivastava, I'll definitely check it.predator2v0

1 Answers

0
votes

Unless, as commented, you are in the wrong repository locally, another cause would be to have created and committed in a new master branch, which differs completely from the upstream one.

This could be related to your issue from two days ago, where you deleted the remote repo, created another, and pushed again.

There are several ways to overcome this issue, the safest being:

  • clone the remote repository in a separate folder
  • compare your local repository with what you have clone in order to re-import any work in progress or past commits you might have in your original local repository.

For example, to check the difference between what you have locally and the remote repository you want to fetch for:

git clone https://github.com/predator2v0/simple-Javascript-calculator /new/path/simple-Javascript-calculator
cd /new/path/simple-Javascript-calculator
git --work-tree=/old/path/to/simple-Javascript-calculator status

That way, you can see if you have any local files (from /old/path/to/simple-Javascript-calculator, you original local repository) with any changes compared to what you have cloned (in /new/path/simple-Javascript-calculator)