Thursday, November 20, 2025

Force Merge Unrelated Histories

 Hi, I have created a git repository named Animals, In that default branch is main. But I have started developing in master branch and pushed all the changes in master branch.

Now, main branch is empty or it has only ReadMe.md file.


Now, I wants to have everything in main branch whatever present in master branch.


In my terminal, I moved to main repository using "git checkout main" and used "git merge master"


Now, I am facing an issue that Unrelated Histories, what should I do now?


Run this command from your main branch:


git merge master --allow-unrelated-histories


This tells Git:

“Yes, I know these branches don’t share a common ancestor — merge anyway.”


Why This Happens:

  • You may have created main and master separately (e.g., cloned, then created a new branch).
  • Git normally expects branches to share a common commit history.

After the Merge:

  • Resolve any merge conflicts if prompted.
  • Commit the merge.
  • Push main to remote:
                    git push origin main

No comments:

Post a Comment

How to Safely Reset Your Local Git Branch to Match the Remote

  How to Safely Reset Your Local Git Branch to Match the Remote Sometimes, your local Git branch contains commits that are already present i...