
% git pull origin my_yellow_branch
From https://github.com/user/myrepo
* branch my_yellow_branch
-> FETCH_HEAD
% git checkout my_yellow_branch
% git merge my_green_branch
fatal: refusing to merge unrelated histories
Reason for the error?
This error occurs when you try to merge two branches that do not share a common ancestor. This would usually happens when you try to merge a branch that was created independently of the branch you are currently on.
Here in the above example we have two branches, my_yellow_branch and my_green_branch, and we are trying to merge my_green_branch into my_yellow_branch. However, my_yellow_branch was created independently and does not have a common ancestor with my_green_branch.
How to fix the error?
Make use of the option (flag) --allow-unrelated-histories
To fix this error, you can use the --allow-unrelated-histories flag when performing a git merge.Using this flag git allows to merge two branches even when they do not have a common ancestor.
Examples:% git checkout my_yellow_branch
% git merge --allow-unrelated-histories branch_to_merge
% git commit -m "Fix: Merged unrelated histories"
% git push origin my_yellow_branch
Reference:
https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---allow-unrelated-historiesHave Questions? Post them here!
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- Github: How to Invite Collaborators
- Git Commit - Author identity unknown, Please tell me who you are email
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- [fix] zsh: command not found: git
- Github: fatal: Authentication failed Support for password was removed on August 13, 2021
- Get List of all local branches git command
- Git Revision Questions Before the Interview
- git fatal: Authentication failed error [fix]
- How to Install Git on Ubuntu Linux
- GitHub: How to Search Code
- How to change Git Default Author and Committer details in Eclipse
- How to check your installed version of Git
- Install GitHub Command Line Tool on Mac
- How to Merge Branch into Master Branch
- Perform an Empty Commit in Git without anything in Staging Area
- Git Fix: fatal: refusing to merge unrelated histories Error
- How to undo last Git Commit on Local Repository?
- git command to remove/unstage files from staging area
- Step-by-Step: Setting up Docker + Ubuntu Linux + Git + GitHub Tutorial
- Remove git config at Local, Global or System Levels?
- Fix [oh-my-zsh] Cant update: not a git repository
- Git Config Command - A Deep Dive
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- How to change directory in Git bash
- Top 10 emerging breakthrough trending technologies - HowTos
- How to the Install Official Android Emulator for Mac? - Android
- Step-by-Step: How to delete a git branch from local as well as remote origin - Git
- M365 service Europe outage - AADSTS90033 A transient error has occurred. Please try again. - Microsoft
- How to turn off Dark Mode in Excel App for Mac - Windows
- How to Hum a Song to Google to find it out! [Android and iPhone] - Google
- Java: Convert Double to 2 Decimal Places [Examples] - Java
- How to check PowerShell version - Powershell