Git Unrelated History
- “Unrelated Histories” is a term used in Git to describe two repositories that have no common history or ancestry. This means that the two repositories were created independently and have no shared commits, branches, or tags.
- In Git, when you try to merge or pull changes from a repository with an unrelated history, Git will not automatically merge the histories. Instead, it will treat the two repositories as completely separate, and you will need to manually merge the changes.
- This situation can arise when you have two repositories that started independently and were never connected, or when you have renamed or reorganized your repository and Git considers the new repository to be a completely separate entity.
- As shown below are the issue dialog box:
fatal: refusing to merge unrelated histories- To resolve “Unrelated Histories” in Git, you can either create a new branch in one repository and merge the changes from the other repository into that branch, or you can manually copy the changes from one repository to the other. In either case, you will need to carefully examine the changes and resolve any conflicts that may arise during the merge.
Run one of the below commands :
# It could be master git pull origin master --allow-unrelated-histories # Or main git pull origin main --allow-unrelated-histories # Or just try with origin git pull origin main --allow-unrelated-histories
If it opens the nano editor you can just save and close with Ctrl + X.
Now push the changes on local
git push origin master
- In summary, “Unrelated Histories” is a situation in Git where two repositories have no common ancestry and cannot be automatically merged. To resolve this issue, you will need to manually merge the changes or create a new branch in one repository to merge the changes into.