Skip to content
Start » git » How to resolve the fatal error refusing to merge unrelated histories

How to resolve the fatal error refusing to merge unrelated histories

the fatal mistake refusing to merge unrelated histories is thrown when trying to automatically merge projects that have different Git histories. since the release 2.9.0 O git does not allow this operation.

The mistake fatal: refusing to merge unrelated histories usually happens when you try to do the git pull from a remote repository, but your local repository has a different history of commits, branches, etc. than the one in the remote repository.

What does it mean git unrelated histories

the error of refuse to merge unrelated stories occurs when a directory .git is unreadable or when you are trying to extract data from a repository with your own commit history.

This error tells you that you are trying to merge with Git two unrelated projects in the same working tree.

One of the reasons could be the start of a local repository and the later addition of the remote that already contains some file, for example a

Others would be when you create a new repository, do some commits and try to pull from another remote repository. This error will be displayed because the local repository you are working with will have a different history than the project you are trying to retrieve.

You may still encounter this error if the directory .git within a project has been deleted or corrupted. In this case, the Git command line may not be able to read the history of your local project.

When trying to push or pull data from a remote repository, this error will occur. This is because Git doesn't know if the remote repository is compatible with your current repository.

How to solve fatal: refusing to merge unrelated histories

To resolve this error just use the option allow-unrelated-histories.

To allow Git to merge two projects with different histories, pass the parameter --allow-unrelated-histories when pulling, like this:

git pull origin master --allow-unrelated-histories

remember to change the remote and branch names to the ones you use in your project

When running the above command line you should be able to run the command git pull or git merge from different histories without any problems, as in the following example:

git pull origin main --allow-unrelated-histories # result Username for '': nunomazer Password for 'https://[email protected]': From /my-project * branch main -> FETCH_HEAD Merge made by the 'recursive' strategy. | 3 +++ 1 file changed, 3 insertions(+) create mode 100644

keep up to date

Don't forget to follow me on twitter and sign the channel on Youtube to receive updates on new articles, video lessons and free courses in software development and engineering.

Leave a Reply

Your email address will not be published.

%d bloggers like this: