简体   繁体   中英

git pull showing error when trying to pull an existing repo in which files were added via upload previously

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.

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM