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.
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.
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.
To resolve this error just use the option
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 'https://gitlab.com': nunomazer Password for 'https://[email protected]': From https://gitlab.com/nunomazer /my-project * branch main -> FETCH_HEAD Merge made by the 'recursive' strategy. README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md
keep up to date