Why Git Says “Unrelated Histories” (And the Fast Fix)


When starting a new project with Github, have you ever faced the issue below?

The issue arises because the branches lack a shared history. While the branches might have identical file names and code, their underlying histories differ. This happens when the original source is added to a brand-new repository instead of being cloned from the original repo.

How to solve this issue?

To solve this issue, run the following commands:

git checkout master   
git branch main master -f    
git checkout main  
git push origin main -f 



To avoid such issues in the future, always ensure that repositories are properly cloned from the original source. This maintains a consistent history between branches, enabling seamless collaboration and version control. Understanding the importance of repository history is crucial for efficient teamwork and maintaining the integrity of your codebase.


Happy Hacking !



Source Image:

https://i.sstatic.net/tNlnM.png

Liked Liked