
% 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-histories-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Git,
- Fix [oh-my-zsh] Cant update: not a git repository
- [fix] fatal: pathspec index.html did not match any files error
- How to ignore files in git using .gitignore file
- Git Fix: fatal: refusing to merge unrelated histories Error
- Install GitHub Command Line Tool on Mac
- How to change directory in Git bash
- Get List of all local branches git command
- fix fatal: --local can only be used inside a git repository error
- [git] fatal: your current branch 'main' does not have any commits yet
- Git Revision Questions Before the Interview
- Change the default git branch name from master to main
- git command to remove/unstage files from staging area
- Remove git config at Local, Global or System Levels?
- [fix] fatal: this operation must be run in a work tree in git
- Clone a particular remote brach using git clone command
- How do I get a list of all branches in Git?
- How to check your installed version of Git
- Step-by-Step: How to delete a git branch from local as well as remote origin
- Git Commit - Author identity unknown, Please tell me who you are email
- 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 Rename a Git Local Branch Using the --move Option
- Perform an Empty Commit in Git without anything in Staging Area
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- GitHub: How to Search Code
- Rename git branch on Local and GitHub Remove using Command
More Posts:
- Cannot open or preview pdf with view only and restricted download access in Microsoft Teams - Teams
- Fix SharePoint 2019 installation error This product requires Visual C++ Redistributable Package for Visual Studio 2017 - SharePoint
- How to know the current version of Java - Java
- How to install Postman natively on a Mac - HowTos
- How to Manage Profile Picture on Microsoft Teams - Teams
- Spring Boot JDBCTemplate Upsert Example (batch insert or update if exists) - Java
- How to display date and time in GMT Timezone in Java - Java
- bash: netstat: command not found - Bash