The displayed error basically occurs in the following situation:
- Changes are made to the remote repository and these changes are not applied to the local repository
In your case, the error message specifies the following:
Updates were rejected because the current branch's endpoint is late compared to the remote repository. Integrate the remote changes (using git pull …
) before "sending" again.
However, if you have created repositories independently, for example: you create the repository in GitHub and also create a local repository with git init
, git can interpret that they are two distinct projects and in these cases you will get the error below:
fatal: refusing to merge unrelated histories
By default, git merge
¹ refuses to merge stories that do not share a common ancestor. This is rare, but if you do, you can use the parameter - -allow-unrelated-histories .
This parameter can be used to override this security by combining stories from two projects that started their lives independently, for example:
git pull origin master --allow-unrelated-histories
Attention! You should not use –allow-unrelated-histories
in all cases, unless you know what an unrelated history is and make sure you need it. Verification was introduced only to avoid disasters when people merge unrelated projects by mistake. ²
¹ The git pull
command is - basically - the join of the git fetch
+ git merge
commands.
Reference:
² link
link